cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

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.

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

net =
countrows ( POs )
)

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors