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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
etane
Resolver I
Resolver I

Calculate Matrix Total by Customer, Product and Calendar Dimensions

Hello.

Please help construct a measure that does the following:
1. Calculate total and subtotal by rep/customer, product and month

2. Forecast has to be last modefied on or before the 15th during the same month as CaseDate1

     
This is my work in progress:

etane_0-1755215675961.png

However, the total should be as below:

etane_1-1755215713652.png

 

Link to working file is here: Link

 

Thanks!

1 ACCEPTED SOLUTION
v-sathmakuri
Community Support
Community Support

Hi @etane ,

 

Thank you for reaching out to Microsoft Fabric Community.

 

Thank you @rohit1991  for your response.

 

Below calculated column will return your expected results. Also attached the pbix file for your reference.

 

Forecast_Selected_Column =

VAR _CurrentMonthStart =

    DATE(

        YEAR(RELATED(Calendar[Date])),

        MONTH(RELATED(Calendar[Date])),

        1

    )

VAR _Cutoff =

    DATE(

        YEAR(_CurrentMonthStart),

        MONTH(_CurrentMonthStart),

        15

    )

VAR _LatestStampInScope =

    CALCULATE(

        MAX(Data[SystemModstamp]),

        FILTER(

            Data,

            Data[Rep] = EARLIER(Data[Rep]) &&

            Data[Product] = EARLIER(Data[Product]) &&

            YEAR(RELATED(Calendar[Date])) = YEAR(_CurrentMonthStart) &&

            MONTH(RELATED(Calendar[Date])) = MONTH(_CurrentMonthStart) &&

            Data[SystemModstamp] >= _CurrentMonthStart &&

            Data[SystemModstamp] <= _Cutoff

        )

    )

RETURN

IF(

    Data[SystemModstamp] = _LatestStampInScope,

    Data[Amount],  -- replace with Forecast column if different

    0

)

 

Thank you!!

View solution in original post

4 REPLIES 4
v-sathmakuri
Community Support
Community Support

Hi @etane ,

 

Thank you for reaching out to Microsoft Fabric Community.

 

Thank you @rohit1991  for your response.

 

Below calculated column will return your expected results. Also attached the pbix file for your reference.

 

Forecast_Selected_Column =

VAR _CurrentMonthStart =

    DATE(

        YEAR(RELATED(Calendar[Date])),

        MONTH(RELATED(Calendar[Date])),

        1

    )

VAR _Cutoff =

    DATE(

        YEAR(_CurrentMonthStart),

        MONTH(_CurrentMonthStart),

        15

    )

VAR _LatestStampInScope =

    CALCULATE(

        MAX(Data[SystemModstamp]),

        FILTER(

            Data,

            Data[Rep] = EARLIER(Data[Rep]) &&

            Data[Product] = EARLIER(Data[Product]) &&

            YEAR(RELATED(Calendar[Date])) = YEAR(_CurrentMonthStart) &&

            MONTH(RELATED(Calendar[Date])) = MONTH(_CurrentMonthStart) &&

            Data[SystemModstamp] >= _CurrentMonthStart &&

            Data[SystemModstamp] <= _Cutoff

        )

    )

RETURN

IF(

    Data[SystemModstamp] = _LatestStampInScope,

    Data[Amount],  -- replace with Forecast column if different

    0

)

 

Thank you!!

Hi @v-sathmakuri .

This is an excellent measure.  I did find an issue when I applied it to my working file.  

The forecast below should be 140,000.  But, because the systemmodstamp date and time is the same for both rows, the measure is combining the two forecast into a single one, 290,000.

etane_0-1755293156461.png

 

Would you be able to tweak the measure so that it takes the Validfromdate as a tie breaker, so only the row with the later Validfromdate forecast row is picked up when there are identical Sysmoddates?

Edit:  Problem solved by using max Validfromdate while still using sysmoddate for cutoff.

 

Hi @etane ,

 

Thank you for confirming your issue got resolved by making small changes.

 

Thanks!!

rohit1991
Super User
Super User

Hi @etane 

 

Could you please follow these steps below :

 

Create Two Measures:

Forecast15thLatest =
VAR MonthDate = MAX ( 'Calendar'[Date] )
VAR Cutoff    = DATE ( YEAR ( MonthDate ), MONTH ( MonthDate ), 15 )
VAR vRep      = SELECTEDVALUE ( Data[Rep] )
VAR vProd     = SELECTEDVALUE ( Data[Product] )
RETURN
IF (
   NOT ISBLANK ( vRep ) && NOT ISBLANK ( vProd ),
   VAR OneRow =
       CALCULATETABLE (
           TOPN (
               1,
               FILTER (
                  ALL ( Data ),
                  Data[Rep] = vRep
                      && Data[Product] = vProd
                      && YEAR ( Data[SystemModstamp] ) = YEAR ( MonthDate )
                      && MONTH ( Data[SystemModstamp] ) = MONTH ( MonthDate )
                      && Data[SystemModstamp] <= Cutoff
               ),
              Data[SystemModstamp], DESC
           )
       )
   RETURN
       MAXX ( OneRow, Data[Amount] )
)
Forecast Selected =
VAR Base = [Forecast15thLatest]
RETURN
SWITCH (
   TRUE(),
   ISINSCOPE ( Data[Product] ),                         
       Base,
   ISINSCOPE ( Data[Rep] ),                             
       SUMX ( VALUES ( Data[Product] ), Base ),
   SUMX ( SUMMARIZE ( Data, Data[Rep], Data[Product] ), [Forecast15thLatest] )
)

Add Forecast Selected into your Matrix.

 

image.png

 


Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.