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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
XuanHau
Helper I
Helper I

Calculate data at max startdate based on slicers

 

Hi,

I need help with my report. I have:

  • A table named A (fact) with 3 columns: group, Start date, quantity.
  • A Datetable and a Grouplist table.
  • Relationships: Startdate-datetable, group-grouplist.

I want to display 2 tables in the report with the slicers Monthyear slicer (from the Datetable), Group slicer (from the grouplist);

  1. Quantity of each group at the maximum start date available in table A
  2. Quantity at the maximum start date available in table A and the maximum date. 

I used this DAX measure:

CALCULATE(SUM(A[Quantity]), FILTER(Datetable, Datetable[Date] = MAX(A[Start Date])))

The totals in the two tables are correct, but the details for each row in the table are not correct. It should show data only for Max start date Feb 8, but it didn't

XuanHau_0-1723455865196.png

I can't upload the pbix file, so i share the link here.

Can someone help me with this? Thanks in advance!

 

7 REPLIES 7
v-mengmli-msft
Community Support
Community Support

Hi @XuanHau ,

 

How do you create the relationship? Could you please show more details about your question?

 

I recommend you try to add all in your current measure.

 

CALCULATE(SUM(A[Quantity]), FILTER(ALL(Datetable), Datetable[Date] = MAX(A[Start Date])))

 

 

If above method doesn’t work, here is another workaround for your reference.

 

Measure = IF( MAX('A'[Start Date]) = MAXX( FILTER(ALL('A' ) , YEAR( 'A'[Start Date] ) = YEAR(MAX('Datetable'[Date]) ) &&  MONTH( 'A'[Start Date] ) = MONTH( MAX('Datetable'[Date]) ) ) , [Start Date]) ,1,0)

 

 

Then set the measure in Filter as bellow.

vmengmlimsft_0-1723450645696.png

 

Here is result of my test.

My table A.

vmengmlimsft_1-1723450663256.png

 

When I select August 2024, the table just shows one record with max StartDate.

vmengmlimsft_2-1723450681529.png

 

 

 

Best regards,

Mengmeng Li

 

Hi @v-mengmli-msft 

The workaround measure works for me, but I have a question: can we include it in a measure instead of using a filter? I also use quantity at the max date in another measure.

I have attached the link to my report in the original post for my example data (this file does not use the workaround you mentioned).

Hi @XuanHau ,

 

I'm afraid can't. The measure just returns a number, it can't be used as Filter in column field. In general, we recommend that user put the measure in Filter and complete the row filter based on the value returned by the measure.😀

 

Best regards,

Mengmeng Li

 

 

Thejeswar
Community Champion
Community Champion

Hi @XuanHau ,

I think whatever is the DAX that you share to get the maximum date quantity is correct. I tried with some dummy data and I was able to get the right numbers with the same DAX query. Find below

 

Max Date Quantity = CALCULATE(SUM(A[QUANTITY]), FILTER(Datetable, Datetable[Date] = MAX(A[Start Date])))

 

For the data with max quantity in each group, you need to have a separate measure

 

Date with Highest Value = 
VAR MAX_QUANTITY = CALCULATE(MAX(A[QUANTITY]), GROUPBY(GroupList, GroupList[Group]))
RETURN
CALCULATE(MAX(A[Start Date]), A[QUANTITY] = MAX_QUANTITY, USERELATIONSHIP(A[Group], GroupList[Group]))

 

 

The Tables are connected as 

  • Relationships: Startdate-datetable, group-grouplist.

Source has data only till 30th August 2024 with only one group per day as shown below

Thejeswar_1-1723449137366.png

 

Source showing the days with Max Data in each group

Thejeswar_3-1723449585014.png

 

DAX output

Thejeswar_2-1723449167018.png

 

Please mark this as solution, if this solves your need! Appreciate a Kudo!

 

Regards,

hi @Thejeswar it seems we have a misunderstanding here. I need the quantity for the max date, not the max quantity in each group
I have already added the link to my PBIX file as an example. I'm not sure if there is something wrong with my DAX measure.

Idrissshatila
Super User
Super User

Hello @XuanHau ,

 

are you sure there's a relationship in the data model between the date table and the table with data on the date column ?



Did I answer your question? Mark my post as a solution! Appreciate your Kudos
Follow me on LinkedIn linkedIn
Vote for my Community Mobile App Idea

Proud to be a Super User!




Hi @Idrissshatila i've checked the relationships multiple times, it still works. So i think the issue comes from my dax

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.