Forum Discussion
Urgent: Inconsistent Row Totals in Power BI Matrix Visual with Custom Logic for Start and End Month
- 1 year ago
This here is a forum where users help users, time permitting. For urgent requests contact a Microsoft partner near you.
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
Please show the expected outcome based on the sample data you provided.
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523 - 1 year ago
Materialize your measure.
- Anonymous1 year ago
Hi lbendlin I've slightly adjusted the logic and its working fine for me now:
Units_in_month =VAR curr_month= MAX('Calendar Table'[Year_Month])VAR days_in_month_ratio=DIVIDE(CALCULATE(COUNTROWS('Slicer'),Slicer[Year_Month]=curr_month),COUNTROWS('Calendar Table'),0)VAR TotalUnits = SUM('Master-Data'[UNIT])VAR StartDate = MIN('Slicer'[Date])VAR DaysInMonth = DAY(EOMONTH(StartDate,0)) -- Number of days in Start DateVAR CurrentDay = DAY(StartDate) -- Current dayVAR difference = ABS(DaysInMonth - CurrentDay)RETURN IF(MIN('Slicer'[Year_Month])=curr_month && CurrentDay<>1,TotalUnits / DaysInMonth * difference,days_in_month_ratio * TotalUnits)Also, adjusted calendar table logic because if we have multiple years of data and then ,if we choose latest year in the date filter then logic for last month column is not working as expected. Just mentionig this here if in case somebody else searching for the soltuion on it..Calendar Table = CALENDAR(Min('Master-Data'[Date]),EDATE(Max('Master-Data'[Date]),12))Thanks for your co-ordination on acheiving the solution lbendlin
Thank You lbendlin Now I can see the calc in first month and last month working as expected in unints_in_months measure. But I'm not seeing the row totals for units_in_months measure. Could you pls. help of fetching the totals for each product wise (row totals).. Example for fridge it should be 0.97+1+0.06 = 2.03.
Materialize your measure.
- Anonymous1 year agoNot applicable
Thanks lbendlin Yes this works! Thanks again for putting effort on solving this!
- Anonymous1 year agoNot applicable
Hi @lbendlin
As I mentoned earlier the logic is working as expected but Year_Month
column in the matrix table is not dynamically updating based on the slicer date selection. In your first approach the column was dynamically changing but in second approach everything works fine except dynamically displaying the year_month based on slicer selection. seems like in UIM measure we need to adjust the logic to dynamically dispaying the year_month based on selection.
Could you pls, revisit this to troubleshoot the issue and find a resolution? Thanks in Advance!
- Anonymous1 year agoNot applicable
Hi lbendlin I created one more measure as below and used this in values section of Matrix. now the columns are displaying dynamically based on date selection. Do we have any other approach other than this ? We need to consider performance as well..
Measure = IF(ISINSCOPE('Calendar Table'[Year_Month]),[Units_in_month],[UIM]) - lbendlin1 year ago
Super User
Not clear to me what your new question is. Maybe create a separate thread?
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
Please show the expected outcome based on the sample data you provided.
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523 - Anonymous1 year agoNot applicable
Hey Hi lbendlin My bad, It seems like I mistakenly tried modifying the logic. So year-months columns was not changing based on date slicer selection and to solve that I was trying out different apporaches using Isinscope functions. But now tried with your second approach without altering the code, I can see the expected result. Now all set, sorry for the confusions!
- Anonymous1 year agoNot applicable
Hi lbendlin Pls. refer to the image below:
The logic for starting month is not working as expected. For remaining monthis its working fine.
Example: selected dates = 2/6/2023 to 1/7/2023
2023-06 Total unit is 1 and for 1/7/2023 also Total unit is 1.
So now for the first month 2023-06 the expected output is 0.94 but this measure gives the result as 0.97 but for last month (1/7/2023) its giving the correct result.
As per my analysis for first month the logic should work as (Totalydaysinfirstmonth-selecteddayinfirstmonth) * totaldaysincalendartable. But the measure used in image calcualtes 30/31 instead of 29/31 for the june month. Could you pls check on the logic for first month alone keeping the rest of the month logics as same. Return same unit for middle of the months and for last month the logic should be Totalunits *(totaldaysinmonth -selectedday)
- Anonymous1 year agoNot applicable
Hi lbendlin Did you get chance to check on this one?
- Anonymous1 year agoNot applicable
Hi lbendlin I've slightly adjusted the logic and its working fine for me now:
Units_in_month =VAR curr_month= MAX('Calendar Table'[Year_Month])VAR days_in_month_ratio=DIVIDE(CALCULATE(COUNTROWS('Slicer'),Slicer[Year_Month]=curr_month),COUNTROWS('Calendar Table'),0)VAR TotalUnits = SUM('Master-Data'[UNIT])VAR StartDate = MIN('Slicer'[Date])VAR DaysInMonth = DAY(EOMONTH(StartDate,0)) -- Number of days in Start DateVAR CurrentDay = DAY(StartDate) -- Current dayVAR difference = ABS(DaysInMonth - CurrentDay)RETURN IF(MIN('Slicer'[Year_Month])=curr_month && CurrentDay<>1,TotalUnits / DaysInMonth * difference,days_in_month_ratio * TotalUnits)Also, adjusted calendar table logic because if we have multiple years of data and then ,if we choose latest year in the date filter then logic for last month column is not working as expected. Just mentionig this here if in case somebody else searching for the soltuion on it..Calendar Table = CALENDAR(Min('Master-Data'[Date]),EDATE(Max('Master-Data'[Date]),12))Thanks for your co-ordination on acheiving the solution lbendlin