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 September 15. Request your voucher.

Reply
ElvirBotic
Helper III
Helper III

Fix Measure to work in Matrix table

Hello, I have a measure counting records created for the year. The simple TOTALYTD function in DAX does not produce the correct result so I learned the hard way sometime ago and used Greg Deckler's version to get YTD and I get the correct result in a card visual, but as soon as I add it to a matrix table it is wrong. I remove the ALL function of result variable and then my total count is wrong, but works in the matrix table. Any advice on how to make it work?

TOTALYTD =
    VAR __Date = MAX('POs 2'[DATE CREATED])
    VAR __StartOf = DATE(YEAR(__Date),1,1)
    VAR __DATESYTD = FILTER(SELECTCOLUMNS(ALL('POs 2'),"Date",[DATE CREATED]),[Date] >= __StartOf && [Date] <= __Date)
RETURN
    COUNTX(
        FILTER(ALL
            ('POs 2'),[DATE CREATED] IN __DATESYTD
            ),
            'POs 2'[PO ID]
        )


Without ALL in the return (Wrong total records)

ElvirBotic_0-1695778903021.png



With ALL added in Return (Correct total, wrong values in cells)

ElvirBotic_1-1695778963835.png

 



2 REPLIES 2
amitchandak
Super User
Super User

@ElvirBotic . Use measures like. Here net is my measure. Always use date table

 

YTD =
var _max = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _min = eomonth(_max,-1*MONTH(_max))+1
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

LYTD =
var _max1 = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _max = Date(Year(_max1)-1, Month(_max1), Day(_max1))
var _min = eomonth(_max,-1*MONTH(_max))+1
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

 

 

Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5b...
To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Is net just countrows of table? or is it a countx? 

net =
countrows ( POs )
)

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 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.