问题在于Power BI中计算SAT指标时 – 聚合结果不正确。

huangapple go评论54阅读模式
英文:

Issue with Calculating SAT Metric in Power BI - Incorrect Aggregated Results

问题

I'm encountering an issue while calculating the SAT (Satisfaction) metric in Power BI. The SAT metric is calculated based on grades received, where grades equal to 9 or 10 are considered positive (Promoters), and grades ranging from 0 to 6 are considered negative (Detractors). The formula I'm using to calculate SAT is as follows:

    SAT =
VAR TotalRows = COUNTROWS(ALLSELECTED(SAT_SHEET))
VAR PromoterRows =
    CALCULATE(
        COUNTROWS(SAT_SHEET),
        SAT_SHEET[GRADE] >= 9 && SAT_SHEET[GRADE] <= 10,
        ALLSELECTED(SAT_SHEET)
    )
VAR DetractorRows =
    CALCULATE(
        COUNTROWS(SAT_SHEET),
        SAT_SHEET[GRADE] >= 0 && SAT_SHEET[GRADE] <= 6,
        ALLSELECTED(SAT_SHEET)
    )
RETURN
    100 * (PromoterRows - DetractorRows) / TotalRows

However, when I try to create a table, matrix, or line chart to display the SAT results aggregated by location, code, or month, the calculation does not yield the correct values. Strangely, when I manually apply filters in Power BI, the SAT calculation produces the expected results. How can I fix my formula to obtain the desired outcome?

英文:

I'm encountering an issue while calculating the SAT (Satisfaction) metric in Power BI. The SAT metric is calculated based on grades received, where grades equal to 9 or 10 are considered positive (Promoters), and grades ranging from 0 to 6 are considered negative (Detractors). The formula I'm using to calculate SAT is as follows:

    SAT =
VAR TotalRows = COUNTROWS(ALLSELECTED(SAT_SHEET))
VAR PromoterRows =
    CALCULATE(
        COUNTROWS(SAT_SHEET),
        SAT_SHEET[GRADE] >= 9 && SAT_SHEET[GRADE] <= 10,
        ALLSELECTED(SAT_SHEET)
    )
VAR DetractorRows =
    CALCULATE(
        COUNTROWS(SAT_SHEET),
        SAT_SHEET[GRADE] >= 0 && SAT_SHEET[GRADE] <= 6,
        ALLSELECTED(SAT_SHEET)
    )
RETURN
    100 * (PromoterRows - DetractorRows) / TotalRows

However, when I try to create a table, matrix, or line chart to display the SAT results aggregated by location, code, or month, the calculation does not yield the correct values. Strangely, when I manually apply filters in Power BI, the SAT calculation produces the expected results. How can I fix my formula to obtain the desired outcome?

I have a dataset containing the following columns:

ID TRANS LOCATION CODE GRADE DATE
1 US RED 10 22/05/2023
2 CAD BLUE 5 23/05/2023
3 LATAM YELLOW 8 24/05/2023
4 UK RED 9 25/05/2023
5 US RED 5 26/05/2023
6 CAD BLUE 4 27/05/2023
7 LATAM BLUE 1 28/05/2023
8 UK BLUE 0 29/05/2023
9 US BLACK 2 30/05/2023
10 CAD RED 5 31/05/2023
11 LATAM BKUE 10 1/06/2023
12 UK YELLOW 10 2/06/2023
13 US RED 10 12/05/2023
14 CAD RED 10 13/05/2023
15 LATAM BLUE 5 4/06/2023
16 UK BLUE 6 1/07/2023
17 US BLUE 8 8/07/2023
18 CAD BLACK 10 26/07/2023
19 LATAM RED 5 8/08/2023
20 UK BKUE 10 22/08/2023
21 US YELLOW 10 13/09/2023
22 CAD RED 5 19/09/2023
23 LATAM RED 8 11/10/2023
24 UK BLUE 10 5/11/2023
25 US BLUE 10 27/11/2023
26 CAD BLUE 10 30/11/2023
27 LATAM BLACK 8 2/12/2023
28 UK RED 9 14/12/2023
29 US BKUE 9 6/01/2024
30 CAD YELLOW 0 12/01/2024

To ilustrate my issue let me show you:

When I apply my SAT to a line chart I get this:

问题在于Power BI中计算SAT指标时 – 聚合结果不正确。

whic is incorrect but If I filter (In a dat filter) my data by month (Mayo) it does give me the proper correct value:

问题在于Power BI中计算SAT指标时 – 聚合结果不正确。

and the same goes for location and code I cant seem to find a way to properly show the resulting SAT by location, code and date in a table viz or in a line viz. How can I fix this issue and correctly display the SAT measure over the months, locations and codes of the dataset?

答案1

得分: 1

Using ALLSELECTED() removes the filter coming from the row context. EG if you write a simple row counting measure like

Rows = countrows(allselected(SAT_SHEET))

You get

问题在于Power BI中计算SAT指标时 – 聚合结果不正确。

So try something like:

    SAT = 
    VAR TotalRows = COUNTROWS(SAT_SHEET)
    VAR PromoterRows =
        CALCULATE(
            COUNTROWS(SAT_SHEET),
            SAT_SHEET[GRADE] >= 9 && SAT_SHEET[GRADE] <= 10
        )
    VAR DetractorRows =
        CALCULATE(
            COUNTROWS(SAT_SHEET),
            SAT_SHEET[GRADE] >= 0 && SAT_SHEET[GRADE] <= 6
        )
    RETURN
        100 * (PromoterRows - DetractorRows) / TotalRows
英文:

Using ALLSELECTED() removes the filter coming from the row context. EG if you write a simple row counting measure like

Rows = countrows(allselected(SAT_SHEET))

You get

问题在于Power BI中计算SAT指标时 – 聚合结果不正确。

So try something like:

    SAT = 
    VAR TotalRows = COUNTROWS(SAT_SHEET)
    VAR PromoterRows =
        CALCULATE(
            COUNTROWS(SAT_SHEET),
            SAT_SHEET[GRADE] &gt;= 9 &amp;&amp; SAT_SHEET[GRADE] &lt;= 10
        )
    VAR DetractorRows =
        CALCULATE(
            COUNTROWS(SAT_SHEET),
            SAT_SHEET[GRADE] &gt;= 0 &amp;&amp; SAT_SHEET[GRADE] &lt;= 6
        )
    RETURN
        100 * (PromoterRows - DetractorRows) / TotalRows

huangapple
  • 本文由 发表于 2023年5月22日 23:47:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76307891.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定