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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
MaheshDadhich
Helper I
Helper I

DAX Function Help

Hello,

 

My requirement is to calculate the MAX  Extractdate(Column Name) for each month in dataset/Table  after applying the user Filter in Power BI Desktop. So Once the dataset is filtered after applying Report parameter then DAX function should calculate the MAX date for each month in dataser which will be used in report.

I have tried ALLEXCEPT function But It calculate the MAX date before filter the data(By User parameter) in dataset which should be after filter the data.

 

For Example :  Below is the Dataset

          

PlantComponentMaterialMonthExtractDateForecast
P1C1M12016015-Jan-1610
P1C1M220160110-Jan-164
P1C1M320160115-Jan-1615
P2C1M420160120-Jan-1611
P2C1M520160125-Jan-1612

 

If User select Plant = P1 and Component = C1 then Max(ExtractDate) should be 15-Jan-16 But in my case It is showing 25-Jan-16.

How to calculate Max date dynamically based on user filter.

 

Thanks in Advance to help me

 

Regards,

Mahesh 

 

 

1 ACCEPTED SOLUTION

Hi @MaheshDadhich,

 

In your scenario, you can specify the expression for MAX Date like below:

 

MAX Date = CALCULATE(MAX('Table1'[Last_Changed_Date]),
             FILTER(ALLSELECTED(Table1),'Table1'[Forecast_Period]=EARLIER(Table1[Forecast_Period])
  && 'Table1'[Plant]=EARLIER(Table1[Plant])))

 

e1.PNGe2.PNG

 

Best Regards,
Qiuyun Yu

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

View solution in original post

3 REPLIES 3
v-qiuyu-msft
Community Support
Community Support

Hi @MaheshDadhich,

 

According to your description, you have added two query parameters to filter both [Plant] and [Component] fields. You want to return maximum date of the column [ExtractDate] when check different parameter values, right?

 

In your scenario, you can create a measure with MAX() function to return the maximum date of the date filed. See:

 

q1.PNGq5.PNG

 

q3.PNGq6.PNG

 

I have attached the test .PBIX file, you can open it in the latest Power BI Desktop to have a look.

 

If you have any question, please feel free to ask.

 

Best Regards,
Qiuyun Yu

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

Hi Qiuyun Yu, Actually my dataset is like that 

 

PlantComponentMaterialForecast_PeriodLast_Changed_DateForecastMAX Date
P1C1M12016055/10/2016105/12/2016
P1C1M22016055/12/2016125/12/2016
P1C1M22016066/25/2016356/27/2016
P1C1M82016066/27/2016706/27/2016
P2 C1M32016055/20/2016205/25/2016
P2 C1M42016055/25/2016505/25/2016
P2 C1M42016066/23/20161006/23/2016

 

If I select Plant = P1 , Component = C1 and Material = ALL the result should be like that with Calculated field MAX Date

 

PlantComponentMaterialForecast_PeriodLast_Changed_DateForecastMAX Date
P1C1M12016055/10/2016105/12/2016
P1C1M22016055/12/2016125/12/2016
P1C1M22016066/25/2016356/27/2016
P1C1M82016066/27/2016706/27/2016

 

 

If I use MAX(Last_Changed_Date)  then It will give max date for entire date which will be 6/27/2016 But I need max date for each Forecast_Period as above.

 

Hi @MaheshDadhich,

 

In your scenario, you can specify the expression for MAX Date like below:

 

MAX Date = CALCULATE(MAX('Table1'[Last_Changed_Date]),
             FILTER(ALLSELECTED(Table1),'Table1'[Forecast_Period]=EARLIER(Table1[Forecast_Period])
  && 'Table1'[Plant]=EARLIER(Table1[Plant])))

 

e1.PNGe2.PNG

 

Best Regards,
Qiuyun Yu

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

Helpful resources

Announcements
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.