Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Urgent: Inconsistent Row Totals in Power BI Matrix Visual with Custom Logic for Start and End Month

Hi There, I'm using matrix visual in my power bi report where column total is coming as expected but row total is not calculating as expected. This is the fields  I used in Matrix visual Matrix...
  • lbendlin's avatar
    lbendlin
    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

  • Anonymous's avatar
    Anonymous
    1 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 Date

    VAR CurrentDay  = DAY(StartDate)     -- Current day

    VAR 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