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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
queryuser
Helper I
Helper I

Display first date based on multiple if statements

Hello everyone,

 

Question: How do I display the first Date using DAX when either Production A or Production B exceeds the values in the Forecast culumn?

 

Thank you!

 

dax.PNG

 

 

1 ACCEPTED SOLUTION

@queryuser you can use this measure

Measure =
MINX (
    CALCULATETABLE (
        VALUES ( 'Table'[Date] ),
        FILTER (
            'Table',
            VAR _prodA =
                CALCULATE ( SUM ( 'Table'[Prod A] ), ALLEXCEPT ( 'Table', 'Table'[Date] ) )
            VAR _prodB =
                CALCULATE ( SUM ( 'Table'[Prod B] ), ALLEXCEPT ( 'Table', 'Table'[Prod B] ) )
            VAR _forecast =
                CALCULATE ( SUM ( 'Table'[Forecast] ), ALLEXCEPT ( 'Table', 'Table'[Date] ) )
            RETURN
                _prodA > _forecast
                    || _prodB > _forecast
        )
    ),
    'Table'[Date]
)

 

smpa01_0-1638891846711.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

9 REPLIES 9
queryuser
Helper I
Helper I

Hello,

 

Tried all 3 solutions without success. Managed to get the dates with my initial formula, with all colums (Prod A & B, Forecast) transformed into measures

 

Maybe you know how to get only one date from the result?

 

First date=
IF(OR([Calc. Sum Production A]>=[Forecast],
[Calc. Sum Production B]>=[Forecast]),
FIRSTDATE(Table1[Date]),"")

 

So now the result looks like that in Power BI - so I need to see only the first date (tried filtering blanks did not work)

 

dax.PNG

 

@queryuser you can use this measure

Measure =
MINX (
    CALCULATETABLE (
        VALUES ( 'Table'[Date] ),
        FILTER (
            'Table',
            VAR _prodA =
                CALCULATE ( SUM ( 'Table'[Prod A] ), ALLEXCEPT ( 'Table', 'Table'[Date] ) )
            VAR _prodB =
                CALCULATE ( SUM ( 'Table'[Prod B] ), ALLEXCEPT ( 'Table', 'Table'[Prod B] ) )
            VAR _forecast =
                CALCULATE ( SUM ( 'Table'[Forecast] ), ALLEXCEPT ( 'Table', 'Table'[Date] ) )
            RETURN
                _prodA > _forecast
                    || _prodB > _forecast
        )
    ),
    'Table'[Date]
)

 

smpa01_0-1638891846711.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Dear  smpa01,

 

The calculation worked well. Yet how would you display the first date as an attribute if for example there would an additional column saying internal or external demand for each of those rows.

 

So that the result is now not the date but the text of the additional column indicating if this is (internal or external) date. 

 

Many thanks in advance!

 

Best regarads,

@queryuser  please create a new thread, provide sample data and expected output.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

@queryuser did you have a chance to look into this?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

I guess you could make a measure from your calculated column with min. This would return The earliest date or on this case of the Blank values cause issues in The min measure consider using If and Make a condition ignoring the blanks.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




ValtteriN
Super User
Super User

Hi,

One easy way to achieve this is to use filtered calculated table as an intermediate step.

My test data (so here we want to get 3.12.2021):

ValtteriN_0-1638872226400.png

Calculated table:
Here I use or to create a filtered table with all the cases where either A or B are greater than forecast

Tempdate = var forecast = max(GetDate[Forecast]) return
FILTER(GetDate,or((GetDate[A])>forecast,GetDate[B]>forecast))
ValtteriN_1-1638872336134.png

Final measure:
Now I just need to get min of the date column in my calculated table.

ValtteriN_2-1638872392410.png

Hope this helps and if it does consider accepting this as a solution!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




rbriga
Impactful Individual
Impactful Individual

First Exceed =
CALCULATE(
MIN( 'Table1'[Date] ),
FILTER(
Table1,
OR(
Table1 [Production A] > Table1 [Forecast],
Table1 [Production B] > Table1 [Forecast]
)
)
)

-------------------------
Data analyst by day, hockey goalie by night.
Did I help? Then please hit that "kudos" or "accept as a solution" button!
amitchandak
Super User
Super User

@queryuser ,

 

Minx(filter(Table, Table[Forecast] < Table[ProductionA] ||Table[Forecast] < Table[ProductionB]), Table[Date])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.