【问题标题】:PowerBI table does not show value when using "Direct query" table使用“直接查询”表时 PowerBI 表不显示值
【发布时间】:2020-09-28 16:03:15
【问题描述】:

我在表 A 和表 B 之间建立了“多对一”关系。 表 A 包含字段 Date、Product、SalesValue,表 B 包含:Product 和 Selection。 样本数据: 表 A(按值自上而下排序):

Date       Product   Subproduct   Value
1-1-2020   Red       A            200
1-1-2020   Red       B            500
1-1-2020   Red       C            600
1-1-2020   Red       D            1500

表 B:

Product  Subproduct    Exclude
Red      A             Yes
Red      B             Yes

当我对表 B 使用“导入模式”时,请在产品上建立多对一关系。 当我使表格可视化时,我的输出将如下:

Date       Product  Subproduct      Value   Exclude
1-1-2020   Red      A                200    Yes
1-1-2020   Red      B                500    Yes
1-1-2020   Red      C                600
1-1-2020   Red      D                1500

但是,当我对表 B 使用“直接查询”模式并在产品上使用多对一关系时。 我的输出如下:

Date       Product  Subproduct       Value  Exclude
1-1-2020   Red      A                200    Yes
1-1-2020   Red      B                500    Yes
1-1-2020   Red      C                
1-1-2020   Red      D                

我的目标是获得以下输出,其中我取最小值并排除指示为“已排除 - 是”的产品。

Date       Product   MinValue  
1-1-2020   Red       600    

我现在正在使用以下 DAX 公式

MinValue = Calculate(Min('TableA'[Value]),'TableB'[Excluded] <> "Yes")

但是,通过这个公式,我得到以下输出:

Date       Product   MinValue  
1-1-2020   Red          

如何在度量中使用“直接查询模式”获得所需的输出作为“导入模式”结果?

谢谢。

【问题讨论】:

    标签: powerbi


    【解决方案1】:

    在下面创建这些 2 措施-

    exclude = 
    
    VAR current_row_product = MIN('Table A'[Product])
    VAR current_row_sub_product = MIN('Table A'[Subproduct])
    
    VAR find_table_B_exclude = 
    CALCULATE(
        MIN('Table B'[Exclude]),
        FILTER(
            ALL('Table B'),
            'Table B'[Product] = current_row_product
                && 'Table B'[Subproduct] = current_row_sub_product
        )
    )
    
    RETURN find_table_B_exclude
    
    exclude_final = 
    
    VAR current_row_value = MIN('Table A'[Value])
    
    VAR Table_A_min_value = 
    CALCULATE(
        MIN('Table A'[Value]),
        FILTER(
            ALL('Table A'),
            'Table A'[exclude] <> "Yes"
        )
    )
    
    RETURN
    if(
        [exclude] = "Yes",
        "Yes",
        IF(
            current_row_value = Table_A_min_value,
            "NO",
            "Yes"
        )
    )   
    

    这是 2 Measure 的输出-

    现在应用可视级别过滤器以仅显示 Final_exclude = NO 且输出如下所示的行-

    -----第2部分----

    在直接查询中,您需要使用带有左连接的查询,如下所示-

    select A.Date,A.Product,A.Value,B.Selection
    from table_a A
    left join table_b B on A.Product = B.Product 
    

    上述查询将在您的列 Value 中保留 GreenYellow 的值,因为您在所需的输出中为它们显示为空白。如果确实有要求,可以使用下面的查询-

    select 
    A.Date,
    A.Product,
    case when B.Selection is null then null else A.Value end as Value,
    B.Selection
    from table_a A
    left join table_b B on A.Product = B.Product 
    

    【讨论】:

    • 您好 mkRabbani,感谢您的回答。我理解你的解决方案。问题是我需要将表 A 保持在导入模式,这个表是一个复杂的查询,需要 10 分钟才能运行。表2,是一个简单的选择qry,我需要直接qry模式,因为它是连接PowerApps的。
    • 然后您可以使用 Measure 或 Power Query Transformation 获得所需的输出。
    • 嗨 mkRabbani,我已经调整了我的请求,并提供了更多细节。感谢您的帮助。
    • 嗨@Zayfaya83,请检查我更新答案的第一部分。
    • 嗨@mkRabbani,我正在尝试重现您的解决方案。但我无法在措施中实现这一行'Table A'[exclude] &lt;&gt; "Yes:exclude_final
    猜你喜欢
    • 2021-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多