Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
I'm trying to figure out how to get the MAX date from a date dimension table. I have three tabels: a fact table that has the datekey and locationkey, date dimension that has the datekey and the date and a location table that has the locationkey and location name. For each location name I need to get the last date there is an entry in the fact table.
For this data:
I want these results
Here are screenshots of the tables:
Locations
DimDates
MyValues fact table
If needed I can share the pbix file too.
Solved! Go to Solution.
Hi @vpoulson
If you want to create a new column then you can use this formula:
Column = CALCULATE(MAX(table_1[Date]),FILTER('table_1',table_1[Location] = EARLIER(table_1[Location])))
If you want to create measure you can use this measure:
maxenddate = CALCULATE(MAX(table_1[EndDate]),REMOVEFILTERS(table_1[EndDate]))
Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Check for more intersing solution here: www.youtube.com/@Howtosolveprobem
Regards
@qqqqqwwwweeerrr Thanks for your contribution on this thread.
Hi @vpoulson ,
@qqqqqwwwweeerrr have provide a good suggestion. You can create different measures as below to get the max date from the dimension date table base on different fact tables, please find the details in the attachment.
MyMaxDate =
VAR _locationkey =
SELECTEDVALUE ( 'Locations'[LocationKey] )
VAR _maxdkey =
CALCULATE (
MAX ( 'MyValues'[DateKey] ),
FILTER ( ALLSELECTED ( 'MyValues' ), 'MyValues'[LocationKey] = _locationkey )
)
RETURN
CALCULATE (
MAX ( 'DimDates'[Date] ),
FILTER ( 'DimDates', 'DimDates'[DateKey] = _maxdkey )
)
TF2MaxDate =
VAR _locationkey =
SELECTEDVALUE ( 'Locations'[LocationKey] )
VAR _maxdkey =
CALCULATE (
MAX ( 'FactTable2'[DateKey] ),
FILTER (
ALLSELECTED ( 'FactTable2' ),
'FactTable2'[LocationKey] = _locationkey
)
)
RETURN
CALCULATE (
MAX ( 'DimDates'[Date] ),
FILTER ( 'DimDates', 'DimDates'[DateKey] = _maxdkey )
)
Best Regards
Hi @vpoulson
If you want to create a new column then you can use this formula:
Column = CALCULATE(MAX(table_1[Date]),FILTER('table_1',table_1[Location] = EARLIER(table_1[Location])))
If you want to create measure you can use this measure:
maxenddate = CALCULATE(MAX(table_1[EndDate]),REMOVEFILTERS(table_1[EndDate]))
Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Check for more intersing solution here: www.youtube.com/@Howtosolveprobem
Regards
Thanks for the help. For this simple data structure both your suggestions work. The actual model I'm working with is a bit more complex. The date and location dimensions are linked to several fact tables. Also the fact table has several other categories that I need to filter by.
If for example if have another fact table that also has a datekey and locationkey is there a way to tell which fact table I want the max date for?
What if my model is like this?
@qqqqqwwwweeerrr Thanks for your contribution on this thread.
Hi @vpoulson ,
@qqqqqwwwweeerrr have provide a good suggestion. You can create different measures as below to get the max date from the dimension date table base on different fact tables, please find the details in the attachment.
MyMaxDate =
VAR _locationkey =
SELECTEDVALUE ( 'Locations'[LocationKey] )
VAR _maxdkey =
CALCULATE (
MAX ( 'MyValues'[DateKey] ),
FILTER ( ALLSELECTED ( 'MyValues' ), 'MyValues'[LocationKey] = _locationkey )
)
RETURN
CALCULATE (
MAX ( 'DimDates'[Date] ),
FILTER ( 'DimDates', 'DimDates'[DateKey] = _maxdkey )
)
TF2MaxDate =
VAR _locationkey =
SELECTEDVALUE ( 'Locations'[LocationKey] )
VAR _maxdkey =
CALCULATE (
MAX ( 'FactTable2'[DateKey] ),
FILTER (
ALLSELECTED ( 'FactTable2' ),
'FactTable2'[LocationKey] = _locationkey
)
)
RETURN
CALCULATE (
MAX ( 'DimDates'[Date] ),
FILTER ( 'DimDates', 'DimDates'[DateKey] = _maxdkey )
)
Best Regards
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
143 | |
85 | |
66 | |
51 | |
45 |
User | Count |
---|---|
216 | |
89 | |
82 | |
66 | |
57 |