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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
zerosugar
Helper II
Helper II

Get Date on which Max or Min Value Occurred?

Hi all, I've been trying for some time to create a measure that gets, for each date of a time series, the date on which the maximum (or minimum) revenue, occurred. 

 

My data looks like this:

Cycle ScenarioDatePredicted QuarterDivisionRevenue
Actuals12/31/2020 Audit74
Actuals3/31/2021 Audit85
Actuals6/30/2021 Audit66
Actuals9/30/2021 Audit76
Actuals12/31/2021 Audit84
Actuals3/31/2022 Audit67
Actuals6/30/2022 Audit94
Actuals9/30/2022 Audit54
Actuals12/31/2020 Management Consulting96
Actuals3/31/2021 Management Consulting70
Actuals6/30/2021 Management Consulting82
Actuals9/30/2021 Management Consulting94
Actuals12/31/2021 Management Consulting57
Actuals3/31/2022 Management Consulting85
Actuals6/30/2022 Management Consulting61
Actuals9/30/2022 Management Consulting99
Q1'22: Positive3/31/2022PQ0Audit67
Q1'22: Positive6/30/2022PQ1Audit79
Q1'22: Positive9/30/2022PQ2Audit67
Q1'22: Positive12/31/2022PQ3Audit62
Q1'22: Positive3/31/2023PQ4Audit86
Q1'22: Positive3/31/2022PQ0Management Consulting85
Q1'22: Positive6/30/2022PQ1Management Consulting66
Q1'22: Positive9/30/2022PQ2Management Consulting83
Q1'22: Positive12/31/2022PQ3Management Consulting69
Q1'22: Positive3/31/2023PQ4Management Consulting87
Q1'22: Negative3/31/2022PQ0Audit67
Q1'22: Negative6/30/2022PQ1Audit77
Q1'22: Negative9/30/2022PQ2Audit95
Q1'22: Negative12/31/2022PQ3Audit77
Q1'22: Negative3/31/2023PQ4Audit83
Q1'22: Negative3/31/2022PQ0Management Consulting85
Q1'22: Negative6/30/2022PQ1Management Consulting62
Q1'22: Negative9/30/2022PQ2Management Consulting55
Q1'22: Negative12/31/2022PQ3Management Consulting87
Q1'22: Negative3/31/2023PQ4Management Consulting98
Q2'22: Positive6/30/2022PQ0Audit94
Q2'22: Positive9/30/2022PQ1Audit84
Q2'22: Positive12/31/2022PQ2Audit65
Q2'22: Positive3/31/2023PQ3Audit70
Q2'22: Positive6/30/2023PQ4Audit94
Q2'22: Positive6/30/2022PQ0Management Consulting61
Q2'22: Positive9/30/2022PQ1Management Consulting78
Q2'22: Positive12/31/2022PQ2Management Consulting97
Q2'22: Positive3/31/2023PQ3Management Consulting98
Q2'22: Positive6/30/2023PQ4Management Consulting50
Q2'22: Negative6/30/2022PQ0Audit94
Q2'22: Negative9/30/2022PQ1Audit86
Q2'22: Negative12/31/2022PQ2Audit80
Q2'22: Negative3/31/2023PQ3Audit66
Q2'22: Negative6/30/2023PQ4Audit68
Q2'22: Negative6/30/2022PQ0Management Consulting61
Q2'22: Negative9/30/2022PQ1Management Consulting57
Q2'22: Negative12/31/2022PQ2Management Consulting55
Q2'22: Negative3/31/2023PQ3Management Consulting81
Q2'22: Negative6/30/2023PQ4Management Consulting94

 

This data of Actual Revenues as well as Revenue Forecasts. The Forecasts begin from an actual date (PQ0) and continue for 4 Quarters. The Forecasts have different Scenarios, like Positive, Negative, or Neutral. 

 

I would like to create a measure that can get, for a visual that groups by "Cycle Scenario" and "Revenue Date", a Column with the maximum date of revenue for that series. I would also like to exclude PQ0 from the calculation for Forecast Series. If there are two dates with the same value, take the first one.

 

Something like this essentially (dates may not be of max revenue, but hope this gets the point across):

 

Cycle ScenarioRevenue DateDate of Max Revenue
Actuals12/31/202012/31/2020
Actuals3/31/202112/31/2020
Actuals6/30/202112/31/2020
Actuals9/30/202112/31/2020
Actuals12/31/202112/31/2020
Actuals3/31/202212/31/2020
Actuals6/30/202212/31/2020
Actuals9/30/202212/31/2020
Q1'22: Negative3/31/20223/31/2023
Q1'22: Negative6/30/20223/31/2023
Q1'22: Negative9/30/20223/31/2023
Q1'22: Negative12/31/20223/31/2023
Q1'22: Negative3/31/20233/31/2023
Q1'22: Positive3/31/20223/31/2023
Q1'22: Positive6/30/20223/31/2023
Q1'22: Positive9/30/20223/31/2023
Q1'22: Positive12/31/20223/31/2023
Q1'22: Positive3/31/20233/31/2023
Q2'22: Positive6/30/202212/31/2022
Q2'22: Positive9/30/202212/31/2022
Q2'22: Positive12/31/202212/31/2022
Q2'22: Positive3/31/202312/31/2022
Q2'22: Positive6/30/202312/31/2022
Q2'22: Negative6/30/20229/30/2022
Q2'22: Negative9/30/20229/30/2022
Q2'22: Negative12/31/20229/30/2022
Q2'22: Negative3/31/20239/30/2022
Q2'22: Negative6/30/20239/30/2022

 

 

I have tried a measure that gets:

 
VAR tempTable = GROUPBY('Table1', 'Table1'[Cycle Scenario], 'Table1'[Revenue Date], "MaxTotal", SUMX(CURRENTGROUP(), 'Table1'[Revenue]))
RETURN
MAXX(tempTable, [MaxTotal])
 
But this is not working. Also, it would only go as far as giving me the max series value for each series. But the GROUPBY() is giving me a table with what I want which is a view of the Series Revenue summarized by Cycle Scenario and Revenue Date. From there I just want to get the date of max or min revenue. Does anyone know how I could do this?
 
Thank you!
2 REPLIES 2
v-rongtiep-msft
Community Support
Community Support

Hi @zerosugar ,

Please refer to my pbix file.

 

Measure = var _1=MAXX(FILTER(ALL('Table'),'Table'[Cycle Scenario]=SELECTEDVALUE('Table'[Cycle Scenario])),'Table'[Revenue])
return
CALCULATE(MIN('Table'[Date]),FILTER(ALL('Table'),'Table'[Cycle Scenario]=SELECTEDVALUE('Table'[Cycle Scenario])&&'Table'[Revenue]=_1))

 

vpollymsft_0-1670552157238.png

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Polly

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

Thank you for the reply. This is close, but it is still not working correctly. This issue is that I don't want to see Business Divisions seperately, I want to see them aggregated. So, if I have a measure that uses ALL('1_MainData') in the MAXX, it will ignore that summing of Business Divisions.

 

I hope this image illustrates the issue:

 

My measure is V1, yours is V2. Note that for V2, it is not choosing the correct value for Actuals - This is because it is looking at the date for which Actuals had the single largest non-aggregate Revenue.My measure is V1, yours is V2. Note that for V2, it is not choosing the correct value for Actuals - This is because it is looking at the date for which Actuals had the single largest non-aggregate Revenue.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

I made some changes to my code and saved it as Max Date V1:

 

Max Date V1 = 
VAR CycleScenarioTag = SELECTEDVALUE('1_MainData'[Cycle Scenario])
-- For Each date in each series, get the Sum of the Business Areas
VAR tempTable = GROUPBY('1_MainData', '1_MainData'[Cycle Scenario], '0_Calendar'[Date], 
    "MaxTotal", SUMX(CURRENTGROUP(), '1_MainData'[Revenue]))
-- Get the Max/Min of a Column in a temp table using MAXX or MINX
VAR myMax = MAXX(tempTable, [MaxTotal])
VAR myMin = MINX(tempTable, [MaxTotal])

RETURN
IF(
    -- If Negative scenario, find date on which Min occurred
    CONTAINSSTRING(SELECTEDVALUE('1_MainData'[Cycle Scenario]), "Negative"),
    MINX(
        FILTER(tempTable, [MaxTotal] = myMin),
        '0_Calendar'[Date]
    ),
    -- Oherwise, get date on which Max occurred
    MAXX(
        FILTER(tempTable, [MaxTotal] = myMax),
        '0_Calendar'[Date]
    )
)

 

Your code is measure "Max Date V2". I can see that my Max Date V1 works in the right chart, where there is no filtering coming from the [Revenue Date] column. However, when I add that filtering, my measure stops working. And I don't know how to remove that filtering because the date I need is coming from a Table Expression (tempTable in my measure).

 

 

In your V2, if you look at "Actuals", it selected 9/3/2022, even when that date had 153, whereas the true highest value is 170, on either 12/31/2020 or 9/30/2021. I am aggregating Audit and Management Consulting Divisions in that view. I think the V2 measure is not accounting for aggregations, as when I de-aggregate, it seems to work. However, my real dataset, I not only have more Divisions, but I also have Sub-Divisions, so this needs to work with an aggregated view.

 

 

Is there a way to remove the [Date] filter? It seems like that might fix the problem, but I'm not sure where something like that would even fit in? I think if I can remove the filter on [Revenue Date] in the GROUP('1_MainData') part of Max Date V1, it could work, but I'm not sure how to do that. ALLEXCEPT() doesn't seem to work and I don't know how to use CALCULATE() to implement REMOVEFILTERS().

 

 

Please let me know if this is sufficient information? Thank you!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.