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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
redface94
Helper I
Helper I

need urgent help with a DAX measure

hi, I would need your assistance because I have to create a measure, to calculate selective based on YTD (e.g. Selective April = YTD April - YTD May. So when I select the month slicer, the selective sum has to be calculated automatically. I already have all the YTD months in columns but also a single YTD column (attached). Capture.PNGScreenshot 2023-06-14 114400.jpgScreenshot 2023-06-14 114539.jpgScreenshot 2023-06-14 114513.jpg

8 REPLIES 8
devanshi
Helper V
Helper V

YTD = TOTALYTD(SUM(Profit), [Date])
selected = 
VAR selectedmonth = SELECTEDVALUE(MONTH([Date]))
RETURN
CALCULATE([YTD],  ALL(datetable),  [Date] = selectedmonth  &&  [Date] > selectedmonth)

redface94
Helper I
Helper I

hi, I tried to adapt the proposed formula, however, unfortunatelly it return 0 as result:
Measure =
VAR currDate =
    MAX ( 'CCA Database'[Reporting Date].[Date] )
RETURN
    IF (
        MONTH ( currDate ) < 12,
        CALCULATE (
            SUM ( 'CCA Database'[Actual YTD]),
            FILTER (
                ALLSELECTED ( 'CCA Database' ),
                YEAR ( 'CCA Database'[Reporting Date].[Date] ) = YEAR ( currDate )
                    && 'CCA Database'[Reporting Date].[Date] <= currDate
            )
        )
            - CALCULATE (
                SUM ( 'CCA Database'[Actual YTD] ),
                FILTER (
                    ALLSELECTED ( 'CCA Database' ),
                    [Reporting Date].[Date] >= DATE ( YEAR ( currDate ), 1, 1 )
                        && [Reporting Date].[Date]
                            <= DATE ( YEAR ( currDate ), MONTH ( currDate ) + 1, DAY ( currDate ) )
                )
            )
    )
Anonymous
Not applicable

Hi @redface94 ,

Can you please share a pbix or some dummy data that keep the raw data structure with expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

hi Xiaoxin, I've tried to attach the excel filr but the system does not accept it, so I paste here some dummy values, in exact the same format which I use:

Value TypeReporting PeriodReporting DateDummy oneDummy 2Calendar Year ResponsibleDummy 3Du,mmy 4Dymmy 5Dummy 6Dyummy 7CountryCountry NameRegionDummy 8Duummy 9Dymmy 10Dymmy 11Dymmy 12Dymmy 13Dymmy 14Dymmy 15Dymmy 16Dymmy 17ActualActual YTDdummy18dummy19dummy20dummy21dummy22dummy23
Cost01.202331/01/20237574504 2023      JPJapanAsia/Pacific          9,186208      
Cost01.202331/01/20232545975 2023      JPJapanAsia/Pacific          3,6686,986      
Cost01.202331/01/20231667412 2023      JPJapanAsia/Pacific          6,4146,699      
Cost01.202331/01/20237798873 2023      JPJapanAsia/Pacific          9,1484,022      
Cost01.202331/01/20234655728 2023      JPJapanAsia/Pacific          217,984      
Cost02.202328/02/20236059819 2023      DEGermanyEurope          5,2288,726      
Cost02.202328/02/2023800714 2023      DEGermanyEurope          2,75410,836      
Cost02.202328/02/20238405864 2023      DEGermanyEurope          8,689171      
Cost02.202328/02/20235597513 2023      DEGermanyEurope          8,630627      
Cost02.202328/02/20233578614 2023      DEGermanyEurope          6,1674,334      
Cost02.202328/02/2023808156 2023      DEGermanyEurope          1531,495      
Cost02.202328/02/20235936417 2023      DEGermanyEurope          8,390245,415      
Cost02.202328/02/20237228652 2023      DEGermanyEurope          7,7032,165      
Cost02.202328/02/20236209322 2023      DEGermanyEurope          6,63757      
Anonymous
Not applicable

Hi @redface94,

I test on the dummy data and find the formula works, anything special exist on your report or Dax expressions?

diff = 
VAR currDate =
    MAX ( 'Table'[Reporting Date])
RETURN
    IF (
        MONTH ( currDate ) < 12,
        CALCULATE (
            SUM ( 'Table'[Actual YTD]),
            FILTER (
                ALLSELECTED ( 'Table' ),
                YEAR ( [Reporting Date] ) = YEAR ( currDate )
                    && [Reporting Date] <= currDate
            )
        )
            - CALCULATE (
                SUM ( 'Table'[Actual YTD] ),
                FILTER (
                    ALLSELECTED ( 'Table' ),
                    [Reporting Date] >= DATE ( YEAR ( currDate ), 1, 1 )
                        && [Reporting Date]
                            <= DATE ( YEAR ( currDate ), MONTH ( currDate ) + 1, DAY ( currDate ) )
                )
            )
    )

Screenshot 2023-06-20 172357.png

Regards,

Xiaoxin Sheng

hello, Is there a possibility to insert here my pbix? becasue the measure still shows 0 unfortunatelly and I can't figure out the reason for it. thank you! 

Dear Xiaoxin, 

 

I checked again and I think I have an issue with the date format. The measure is working but when I add the date in the table, there is an error (will attach it). Also, the measure displays 0 when I remove Actual and Actual YTD columns and I will need only the difference to be displayed in a separate table. I will attach also a screenshot of my date format. thank you so much!Screenshot 2023-06-21 121043.jpgScreenshot 2023-06-21 121510.jpgScreenshot 2023-06-21 121128.jpgScreenshot 2023-06-21 121111.jpg

Anonymous
Not applicable

HI @redface94,

You can try to use the following measure formula to get the difference between current and following month YTD:

formula =
VAR currDate =
    MAX ( Calendar[Date] )
RETURN
    IF (
        MONTH ( currDate ) < 12,
        CALCULATE (
            SUM ( Table[Value] ),
            FILTER (
                ALLSELECTED ( Table ),
                YEAR ( [Date] ) = YEAR ( currDate )
                    && [Date] <= currDate
            )
        )
            - CALCULATE (
                SUM ( Table[Value] ),
                FILTER (
                    ALLSELECTED ( Table ),
                    [Date] >= DATE ( YEAR ( currDate ), 1, 1 )
                        && [Date]
                            <= DATE ( YEAR ( currDate ), MONTH ( currDate ) + 1, DAY ( currDate ) )
                )
            )
    )

Regards,
Xiaoxin Sheng

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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