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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Use a measure to display category values in a matrix, but average values for a single category.

Hi, hope someone can help. I want to show values for categories, but for a single category "Nød", the values must be averages for the value in Takst_1 and Takst_2.
My test data is seen in "Rådata" and the desired result in "Nødkald korrigeret i data".

 

Rådata.pngMatrix.png

 

I can solve the problem in my query with GROUPBY and an IF statement that places different values in a calculated column.

But how do you do the same with a measure?

 

let
    Kilde = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8qhMV9JRCknMLi6JNwSyDHUMQZRjUmqOUqxOtJLf4R0p6AqQ5QNyUtGljZHlkc03ArKMdYxxGo9FHtl4LNLorgcip8ykTOwuR5ZEd7aRjhGyNLqrTXRMcBqNRR7d1cjSsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Indsats = _t, Takst = _t, Værdi = _t, ID = _t]),
    #"Ændret type" = Table.TransformColumnTypes(Kilde,{{"Værdi", type number}}),
    #"Grupperede rækker" = Table.Group(#"Ændret type", {"ID", "Indsats"}, {{"SumVærdi", each List.Sum([Værdi]), type nullable number}, {"Alle", each _, type table [Indsats=nullable text, Takst=nullable text, Værdi=nullable number, ID=nullable text]}}),
    #"Udvidet Alle" = Table.ExpandTableColumn(#"Grupperede rækker", "Alle", {"Takst", "Værdi"}, {"Takst", "Værdi"}),
    #"Tilføjet brugerdefineret" = Table.AddColumn(#"Udvidet Alle", "KorrVærdi", each if [Indsats] = "Nød" then [SumVærdi] / 2 else [Værdi]),
    #"Ændret type1" = Table.TransformColumnTypes(#"Tilføjet brugerdefineret",{{"KorrVærdi", type number}})
in
    #"Ændret type1"

 

 

 

Best regards

Søren

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hello @Anonymous 
I think below mentioned DAX Query may help to resolve the query:

Measure_Værdi =
IF (
SELECTEDVALUE ( 'Rådata'[Indsats] ) = "Nød",
CALCULATE (
DIVIDE ( SUM ( 'Rådata'[Værdi] ), CALCULATE(DISTINCTCOUNT( 'Rådata'[Takst]),ALL('Rådata')) ),
REMOVEFILTERS ( 'Rådata'[Takst] )
),
SUM ( 'Rådata'[Værdi] )
)

 

Thank You!

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @Anonymous ,
Inbuilt Total column of matrix in Power BI Desktop will consider the values as per data table rather than considering the average value. So will have to make another measure for total which will add values of all ID with condition for our particular IndStats to consider average value.

 

Anonymous
Not applicable

Hi @Anonymous ,
Can you explain SELECTEDVALUE query?
and if query is resolved please accept it as a solution😊

Anonymous
Not applicable

Hi Muskan

Thank you for the reply.
It seems the SELECTEDVALUE is not working correctly when there is both ID and Indsats as rows in the matrix.

Best regards
Søren

Anonymous
Not applicable

Hello @Anonymous 
I think below mentioned DAX Query may help to resolve the query:

Measure_Værdi =
IF (
SELECTEDVALUE ( 'Rådata'[Indsats] ) = "Nød",
CALCULATE (
DIVIDE ( SUM ( 'Rådata'[Værdi] ), CALCULATE(DISTINCTCOUNT( 'Rådata'[Takst]),ALL('Rådata')) ),
REMOVEFILTERS ( 'Rådata'[Takst] )
),
SUM ( 'Rådata'[Værdi] )
)

 

Thank You!

Anonymous
Not applicable

I have made the measure work perfectly - thank you very much for the help.


But I have discovered another problem - when the measure is used, my totals do not show what they should. (see the table with the query solution).

Totaler.png
I think I should have the measure wrapped in an IF statement as suggested in this article: Dealing with Measure Totals - Microsoft Power BI Community 


But I can not quite figure it out - can you help?

 

Best Regards
Søren

Helpful resources

Announcements
ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.