Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Displaying number of measures depending on their values

Hi,

 

I have a table with goals and achievements (real data have more levels than just group and id) :

groupidgoalach
Aa1102
Aa257
Aa310098
Bb16025
Bb232
Cc157
Cc21028

I must calculate a rate of achievement (achievement / goal).

 

I use a measure for that because I need to be able to aggregate this rate at mutliple levels :

 

 

 

mtx = DIVIDE(SUM(data[val]), SUM(data[obj]))

 

 

 

This is working as expected.

 

Depending on this rate, I then need to classify the data : 

  • rate < 50% == bad
  • 50% <= rate < 100% == correct
  • 100% <= rate == good

I use another measure :

 

 

cat = SWITCH(TRUE(), [mtx] < 0.5, "bad", [mtx] < 1, "correct", "good")

 

 

 

Now, I have something like :

groupidgoalachmtxcat
Aa110220%bad
Aa257140%good
Aa31009898%correct
Bb1602541.67%bad
Bb23266.67%correct
Cc157140%good
Cc21028280%good

 

If I aggregate by group, the values are correctly calculated :

groupgoalachmtxcat
A11510793.04%correct
B632742.86%bad
C1535233.33%good

 

Finally, I'd like to display the number of bad, correct and good depending on the filter I may have.

For example, If I only display group A (using a segment), I need to have one correct and zero bad or good.

 

But all my tests were unsuccessful. Usually, I end up counting the number of category on the lowest level of the table (a1, a2, ...) and not on the group level. I did also try to create another table with SUMMARIZECOLUMNS but didn't manage to make it work either.

 

I attached a simple pbix with some data here : test_cat.pbix

 

Thank you for your help.

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

you cannot measure a measure. You will have to create an entirely new measure for that second scenario, and use aggregator functions.

Table = UNION(ROW("Category","bad"),ROW("Category","correct"),ROW("Category","good"))

Measure = 
var a=ADDCOLUMNS(values(data[id]),"m",[cat])
return COUNTROWS(filter(a,[m]=SELECTEDVALUE('Table'[Category])))

 

See attached.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi,

 

thank you both for the examples. I'll try to implement that in my report and let you know.

 

Both approachs are interesting ; I'm just a bit afraid of all that ADDCOLUMNS functions (they will manipulate a lot of data).

 

(I put the file back online just in case)

tamerj1
Super User
Super User

Hi @Anonymous 
The link is not working. However you can try the following

Correct =
VAR T1 =
    ADDCOLUMNS ( Data, "@mtx", [mtx] )
VAR T2 =
    ADDCOLUMNS (
        T1,
        "@cat",
            SWITCH ( TRUE (), [@mtx] < 0.5, "bad", [mtx] < 1, "correct", "good" )
    )
VAR Result =
    SUMX ( T2, IF ( [@cat] = "correct", 1 ) )
RETURN
    Result
Good =
VAR T1 =
    ADDCOLUMNS ( Data, "@mtx", [mtx] )
VAR T2 =
    ADDCOLUMNS (
        T1,
        "@cat",
            SWITCH ( TRUE (), [@mtx] < 0.5, "bad", [mtx] < 1, "correct", "good" )
    )
VAR Result =
    SUMX ( T2, IF ( [@cat] = "good", 1 ) )
RETURN
    Result
Bad =
VAR T1 =
    ADDCOLUMNS ( Data, "@mtx", [mtx] )
VAR T2 =
    ADDCOLUMNS (
        T1,
        "@cat",
            SWITCH ( TRUE (), [@mtx] < 0.5, "bad", [mtx] < 1, "correct", "good" )
    )
VAR Result =
    SUMX ( T2, IF ( [@cat] = "bad", 1 ) )
RETURN
    Result
lbendlin
Super User
Super User

you cannot measure a measure. You will have to create an entirely new measure for that second scenario, and use aggregator functions.

Table = UNION(ROW("Category","bad"),ROW("Category","correct"),ROW("Category","good"))

Measure = 
var a=ADDCOLUMNS(values(data[id]),"m",[cat])
return COUNTROWS(filter(a,[m]=SELECTEDVALUE('Table'[Category])))

 

See attached.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors