Forum Discussion

queryuser's avatar
queryuser
Helper I
4 years ago
Solved

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!

 

 

 

  • smpa01's avatar
    smpa01
    4 years ago

    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]
    )
    

     

     

9 Replies

  • queryuser ,

     

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

  • rbriga's avatar
    rbriga
    Impactful Individual

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

  • ValtteriN's avatar
    ValtteriN
    Community Champion

    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):

    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))

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

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

  • 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)

     

     

    • smpa01's avatar
      smpa01
      Community Champion

      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]
      )
      

       

       

    • ValtteriN's avatar
      ValtteriN
      Community Champion

      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.