Forum Discussion

SonyT01's avatar
SonyT01
Regular Visitor
5 years ago
Solved

How to write an IF measure when using different time periods

Hi,   Please can someone show me how to write the following IF measure.    I have an example where I have created a table in Power BI that looks similar to the below.  I have calculated a 'YTD' f...
  • DataInsights's avatar
    5 years ago

    SonyT01,

     

    Try this measure:

     

    YTD New = IF ( MAX ( Table1[Name] ) = "Cash", [YTD Mar 2020], MAX ( Table1[YTD] ) )

     

  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi SonyT01 ,

     

    According to your description and my previous experience, I guess you seem to mix measures and calculated columns. It does not meet the definition rules of DAX functions.

    This error can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

    Result:

     

    I think you can modify the "YTD NEW" measure appropriately as follows.

     

    YTD NEW =

                      var min_value=MIN('Table 1'[Name])

                      return

                     IF(

                            min_value="cash",

                            'Table 1'[YTD Mar 2020],

                           MIN('Table 1'[YTD])

                         )

     

    Result:

     

    I hope my suggestion can give you some help.

     

    Best Regards,

    Yuna

     

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

     

  • SonyT01's avatar
    SonyT01
    5 years ago

    Thank you so much!!  I have been trying to figure this out with no success.  This has achieved the result I was after.

     

    Many thanks again!