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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register 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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.