Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

When data for a calendar day is missing ... Power Query or DAX solution?

I have a table that should provide a row per calendar day and is refreshed several times a day. The data is the current stock level of a warehouse. Based on the data, two measures make a simple 7-day simulation of expected warehouse space. The calculation is cumulative and quite straightforward and the main measure is below. 

 

Occasionally there isn't a row for "NetOfDeliveryCollection" on a calendar day so the simulation goes awry. I think I just need to add a value of zero for that missing day but my quesiton is how? Should I create a fake row in the dataload script or just add an IF condition in the DAX.

 

Either method, I don't know how to do this! 

 

Measure = SUM(DailyBalances[CurrBalance])
+ CALCULATE(
SUM(Delivery[NetOfDeliveryCollection])
, FILTER(
ALLSELECTED(Delivery)
,Delivery[DelDate] <= MAX(Delivery[DelDate])
)
)

  • Hi, Anonymous 

     

    You can add IF conditions to the DAX. This is shown below.

    Measure =
    VAR N1 =
        SUM ( DailyBalances[CurrBalance] )
            + CALCULATE (
                SUM ( Delivery[NetOfDeliveryCollection] ),
                FILTER (
                    ALLSELECTED ( Delivery ),
                    Delivery[DelDate] <= MAX ( Delivery[DelDate] )
                )
            )
    VAR N2 =
        SUM ( DailyBalances[CurrBalance] ) + 0
    RETURN
        IF ( SELECTEDVALUE ( Delivery[NetOfDeliveryCollection] ) = BLANK (), N2, N1 )
    

     Please try this formula, does this match your desired result?

     

    Best Regards,

    Community Support Team _Charlotte

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

2 Replies

  • v-zhangti's avatar
    v-zhangti
    Community Support

    Hi, Anonymous 

     

    You can add IF conditions to the DAX. This is shown below.

    Measure =
    VAR N1 =
        SUM ( DailyBalances[CurrBalance] )
            + CALCULATE (
                SUM ( Delivery[NetOfDeliveryCollection] ),
                FILTER (
                    ALLSELECTED ( Delivery ),
                    Delivery[DelDate] <= MAX ( Delivery[DelDate] )
                )
            )
    VAR N2 =
        SUM ( DailyBalances[CurrBalance] ) + 0
    RETURN
        IF ( SELECTEDVALUE ( Delivery[NetOfDeliveryCollection] ) = BLANK (), N2, N1 )
    

     Please try this formula, does this match your desired result?

     

    Best Regards,

    Community Support Team _Charlotte

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

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks, this answered my question of how to add an IF into a DAX. For the record, your formula  didnt solve my problem but you have answered my question.