Forum Discussion
Summin a calculated weighted average in a Matrix Column subtotal
- 7 years ago
Hi cschuchert
You may refer to below measure.
Totals = SUMX ( 'TableA', TableA[Forecast_Value] * TableA[DaysInMth] ) / SUMX ( 'TableA', TableA[DaysInMth] )Subtotal = VAR a = SUMMARIZE ( TableA, TableA[Division], "b", [Totals] ) RETURN SUMX ( a, [b] )Regards,
Cherie
- 7 years ago
You are a genius!! I saw your post where it looked like I hadn't sent the data-I'm not sure what happened to my post with the excel data but it's there now.
I cannot thank you enough!! I'll have to research SUMMARIZE so I understand how to apply it to other visualizations.
Regards,
Carolyn
See screenshots. Let me know if you only wanted the data.
AfterBeforeExpected Outcome
- Anonymous7 years agoNot applicable
Hello cschuchert,
Now I understand what You need.
The aswer is pretty simple after you discover, and you will be making the same fix a lot of times =).
The DAX is doing the same measure you create for the totals, It consider the total line as another row in the table, that way the results in error for you that want the totals of lines.
For this treatment you will need to tell DAX that if you filter the column "Product_Type" you want the sum of row.
You will use IF plus HASONEFILTER or ISFILTERED, you chose one or another.
Like:
Measure = IF ( ISFILTERED ( ColumnName[Product_Type] ) ; Sum(TableName[Category] ; SUMX ( 'Table', Table[Forecast_Value] * Table[DaysInMth]) / SUMX ( 'Table', Table[DaysInMth] ) )
Cheers,
- cschuchert7 years agoFrequent Visitor
The Matrix in my screenshots is only filtered by the Quarter. I also have multiple slicers on the page for the Forecast week, Division, ProductType and Quarter used in another Matrix on the same page. The Matrix using the meaure is to get a CWA for each Quarter; all filters work on both Matrixes.
If I filter this to one Division the Total is correct but if all Divisions are selected the Total is the Average.
What exactly is Sum(TableName[Category] doing in the measure example? I understand an IF statement needs a True/False but all I really want is for this measure to Sum the values used in my original measure.
- v-cherch-msft7 years ago
Microsoft Employee
Hi cschuchert
You may have a look at below posts. If you need further help, please share some simplified data sample.
How to Get Your Question Answered Quickly
https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376
Regards,
Cherie