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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
rob_vander2
Helper II
Helper II

take max date from calendar table and pass it to fact table

Hi All,

 

I have two tables. Fact table and calendar table. Both tables are linked on date. My requirement is, I want to show sales value from fact table on latest date in KPI. Note that user can select any specific date from calendar, so sales value should reflect that value as well. How do I write DAX measure to achive this? I tried below

VAR  max_date = max(fact_table[business_date])
return
calculate ( sum(fact_table[sales])), fact_table[business_date] = max_date)


This works by default, but when I select any date from calendar, it shows blank. I want to show the value for that specific date

5 REPLIES 5
Praful_Potphode
Resolver II
Resolver II

Hi @rob_vander2 

since you have calendar table ,all the date filters should be written on that.calendar table is connected to your fact so if you filter calendar, it will eventually filter fact.

please try below measure and let me know if it works.

 

Measure=
VAR  max_date = max(Calendar[date])
return
calculate ( sum(fact_table[sales])),ALL(Calendar), Calendar[date] = max_date)

the ALL function removes all filters from calendar table.then it applies the max date filter.

for this to work create your date slicer on calendar.

 

Please give kudos or mark it as solution once confirmed.

 

Thanks and Regards,

Praful

Nasif_Azam
Super User
Super User

Hey  @rob_vander2 ,

To meet the requirement where the sales value reflects the selected date from the calendar and also displays the sales for the latest date, you can try the DAX measure like this:

 

SalesOnSelectedDate :=
VAR SelectedDate = MAX('Calendar'[Date]) 
VAR MaxDate = CALCULATE(MAX('FactTable'[BusinessDate]), ALL('FactTable'))
VAR DateToUse = IF(SelectedDate = BLANK(), MaxDate, SelectedDate)
RETURN
CALCULATE(SUM('FactTable'[Sales]), 'FactTable'[BusinessDate] = DateToUse)

 

Best Regards,
Nasif Azam



Did I answer your question?
If so, mark my post as a solution!
Also consider helping someone else in the forums!

Proud to be a Super User!


LinkedIn
Jihwan_Kim
Super User
Super User

Hi, I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

I tried to show latest date sales per each country, and each country shows different latest date. And I tried to use TREATAS DAX function in the measure.

 

TREATAS function - DAX | Microsoft Learn

 

Jihwan_Kim_1-1760248180621.png

 

 

Jihwan_Kim_0-1760248135418.png

 

Last date sales: =
VAR _periodselect =
    MAX ( 'calendar'[Date] )
VAR _t =
    SUMMARIZECOLUMNS (
        country[country],
        'calendar'[Date],
        FILTER ( ALL ( 'calendar' ), 'calendar'[Date] <= _periodselect ),
        "@sales", SUM ( fact_table[sales] )
    )
VAR _latestdate =
    ADDCOLUMNS (
        _t,
        "@latestdate",
            MAXX (
                FILTER ( _t, country[country] = EARLIER ( country[country] ) ),
                'calendar'[Date]
            )
    )
VAR _treatas =
    SUMMARIZE ( _latestdate, country[country], [@latestdate] )
RETURN
    CALCULATE (
        SUM ( fact_table[sales] ),
        TREATAS ( _treatas, country[country], 'calendar'[Date] )
    )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Kedar_Pande
Super User
Super User

  

Your measure uses the fact table date. Use the calendar table date instead.

 
Sales Measure =
VAR SelectedDate = MAX('Calendar'[Date])
RETURN
CALCULATE(
SUM(fact_table[sales]),
fact_table[business_date] = SelectedDate
)

@rob_vander2

v-nmadadi-msft
Community Support
Community Support

Hi @rob_vander2 

I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions.


Thank you.

Helpful resources

Announcements
November Fabric Update Carousel

Fabric Monthly Update - November 2025

Check out the November 2025 Fabric update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Users online (27)