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
Yael
Helper IV
Helper IV

DAX - max function that takes filters into consideration dynamically

Hello,

 

Need help with DAX function please.

Below is a pic of my data source, I'm interested in populating the field "Is Maximum Date" with 1 / 0 values.

Row NumberDateTransaction NumberCustomerCustomer CategoryIs Maximum Date
16-Mar-18100A-JohnA 
26-Mar-18200B-KimB 
37-Mar-18300A-JohnA 
47-Mar-18400A-JohnA 

I want that field to be calculated according to filters applied by the user -

If user select in filter Customer = "A-John", I want to see Is Maximum Date =1 for row 3 and 4

If user select in filter Customer Category = "B", I want to see Is Maximum Date =1 for row 2

and so on...

How can I do this please?

 

Thanks!

8 REPLIES 8
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @Yael,

 

Please check out a demo here.

1. You need dimensional tables in your scenario.

2. Two slicers.

3. The measure could be like this:

Measure =
VAR maxdate =
    CALCULATE ( MAX ( 'Table1'[Date] ), ALL ( 'Table1'[Row Number] ) )
RETURN
    IF ( MIN ( 'Table1'[Date] ) = maxdate, 1, 0 )

DAX_max_function_that_takes_filters_into_consideration_dynamically

 

Best Regards,

Dale

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

Thanks @v-jiascu-msft. Tried creating the measure in the DateDim:

IsMaxDate =
VAR maxdate =
CALCULATE (MAX(dim[Date]), ALL(dim[DatePK]))
RETURN
IF (MAX(dim[Date]) = maxdate, 1, 0 )

When I drag this measure to my fact table, I see that it's duplicating the rows for dates that don't exist in the fact + all rows are getting 1 in "IsMaxDate"

Measure.jpg

HI @Yael

 

Try this one

 

IsMaxDate =
VAR maxdate =
    CALCULATE ( MAX ( dim[Date] ), ALLSELECTED () )
RETURN
    IF ( MAX ( dim[Date] ) = maxdate, 1, 0 )

Now I recieve 1 in one row only, but the fact still displays rows for all dates (even those which don't exist in the fact):

Measure 2.jpg

Any other ideas on how we can create a general function that calculates MAX and Min according to values in filters / slicers?

GeorgeBuster
Advocate III
Advocate III

Hi Yael,

 

On the one hand, you can't create calculated columns depending on report filters because the values of these columns are calculated when the data is loaded before the user select the filter.


On the other hand, if you want to fill your column with 1/0, where 1 is once per user we can do it:


Is Maximum Date =
VAR CUSTOMER = MAX(Customer)
RETURN
IF(
    Date = CALCULATE(
                MAX(Date);
                ALL(TransactionsTable);
                Customer = CUSTOMER
           );
    1;
    0
)

 

Hope this can help you,

Jorge.

Thanks @GeorgeBuster! the above DAX ereturns an error message, not specifing where is the issue...

Could you share a screenshot? Maybe we can find the error. Thanks.

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.