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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
rjekrej
Frequent Visitor

Question regarding MAX DAX formula concerning date table and fact table

Hi everyone 

 

I have a star schema model where i have some dimension tables and a fact table. The dates in the dimension date table go to the end of the year 2025. The fact table date is always to days date.

 

I want to calculate visits year-to-date but the formula below (v.1) does not work but v.2 do. Can anyone explain why v.2 works and v.1 does not?

 

YTD (v.1) =
CALCULATE ( [Visits], DATESYTD ( Dim_dato[Date] ) )

 

YTD (v.2) =
CALCULATE (
    CALCULATE ( [Visits], DATESYTD ( Dim_dato[Date] ) ),
    Dim_dato[Date] <= MAX ( 'Fact_besøg'[Date] )
)

 

 

3 REPLIES 3
v-rzhou-msft
Community Support
Community Support

Hi @rjekrej ,

 

Normally, if your Dim_dato table has continuous single date and is connected to Fact_besøg table, DATESYTD() should work in this situation.

My Sample:

RicoZhou_0-1675758622892.png

Dim_dato = CALENDARAUTO() 

RicoZhou_1-1675758647045.png

Result is as below.

RicoZhou_2-1675758664077.png

You can check whether your data model is same as mine. Your issue should be caused by the calculation logic of [Visit] measure. In my sample, [Visit] measure is only a sum measure. You can check yours as well.

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi 

 

Thank you very much for you help. It was great, it works. In my calender dim table i have a value for the date 1/1/1900 ( i cannot remove it) along with date values for the year 2022 and 2023. Do you know in DAX how exclude the 1/1/1900 and still make the formula work? 

amitchandak
Super User
Super User

@rjekrej , You can try measure like

 

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))

 

 

or

 

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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