Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Reference a Price from the same Table

Hi,

 

I am trying to achive a measure in which Price of the select the month should be displayed, if the Price is not available in that month then it should show case the Next available price
 

I have Used a unlink calendar for the reference Month Year selection

This is the Requirement:

Materialplant CustomerDateSales PriceReference Price 1-03-2020
M0001P001CSM00101-01-20209069
M0001P001CSM00101-02-20208969
M0001P001CSM00101-03-20206969
M0001P001CSM00101-06-20209069
M0001P001CSM00101-07-20201869
M0001P001CSM00101-08-20208269
M0001P001CSM00101-09-20205669
M0002P001CSM00101-01-20209064
M0002P001CSM00101-02-20209964
M0002P001CSM00101-07-20206464
M0002P001CSM00101-08-20202264

 

 

The Measure that i am trying to build:

ReferencePeriod = SELECTEDVALUE( 'Calendar Table'[Start of Month] )

ReferencePrice = VAR ReferencePeriod = [ReferencePeriod]

VAR ReferenceTable =

    SUMMARIZE (

        CALCULATETABLE ( ‘Table’, ‘Table’[Date] >= ReferencePeriod, REMOVEFILTERS(Date)),

        ‘Table’[Plant],

        ‘Table’[Material],

        ‘Table’[Customer],

        "SalesPrice",

            VAR Price =

                CALCULATE (

                    MAX ( ‘Table’[Sales Price] ),

                    ‘Table’[Date] = ReferencePeriod,

                    REMOVEFILTERS ( DimDate )

                )

            VAR PriceMPlus1 =

                CALCULATE (

                    MAX ( ‘Table’[Sales Price] ),

                    ‘Table’[Date] = EDATE ( ReferencePeriod, 1 ),

                    REMOVEFILTERS ( DimDate )

                )

            VAR PriceMPlus2 =

                CALCULATE (

                    MAX ( ‘Table’[Sales Price] ),

                    ‘Table’[Date] = EDATE ( ReferencePeriod, 2 ),

                    REMOVEFILTERS ( DimDate )

                )

            VAR PriceMPlus3 =

                CALCULATE (

                    MAX ( ‘Table’[Sales Price] ),

                    ‘Table’[Date] = EDATE ( ReferencePeriod, 3 ),

                    REMOVEFILTERS ( DimDate )

                )

            RETURN

                SWITCH (

                    TRUE (),

                    NOT ( ISBLANK ( Price ) ), Price,

                    ISBLANK ( Price ), PriceMPlus1,

                    ISBLANK ( PriceMPlus1 ), PriceMPlus2,

                    ISBLANK ( PriceMPlus2 ), PriceMPlus3,

                    Price

                )

    )

RETURN

    SUMX ( ReferenceTable, [SalesPrice] )

 

  • Hi , Anonymous 

    According to your description, you want to achive a measure in which Price of the select the month should be displayed, if the Price is not available in that month then it should show case the Next available price.

    Here are the steps you can refer to :
    (1)This is my test data:

    I create a calendar table like this:

    (2)We can create a measure like this:

    Measure = var _slicer = MIN('Calendar'[Date])
    var _has_value =MAXX( FILTER( 'Table' , 'Table'[Date]=_slicer) , [Sales Price])
    var _no_value_date = MINX(  FILTER('Table' , 'Table'[Date]>_slicer) , [Date])
    var _no_value =MAXX( FILTER('Table' , 'Table'[Date] = _no_value_date) , [Sales Price])
    return
    IF(_has_value=BLANK(),_no_value,_has_value)

     

    (3)Then we can put the measure on the visual and we can meet your need:

     

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

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

     

3 Replies

  • Hi , Anonymous 

    According to your description, you want to achive a measure in which Price of the select the month should be displayed, if the Price is not available in that month then it should show case the Next available price.

    Here are the steps you can refer to :
    (1)This is my test data:

    I create a calendar table like this:

    (2)We can create a measure like this:

    Measure = var _slicer = MIN('Calendar'[Date])
    var _has_value =MAXX( FILTER( 'Table' , 'Table'[Date]=_slicer) , [Sales Price])
    var _no_value_date = MINX(  FILTER('Table' , 'Table'[Date]>_slicer) , [Date])
    var _no_value =MAXX( FILTER('Table' , 'Table'[Date] = _no_value_date) , [Sales Price])
    return
    IF(_has_value=BLANK(),_no_value,_has_value)

     

    (3)Then we can put the measure on the visual and we can meet your need:

     

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

    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

    Hi,

     

    Thanks for the Response it was very Helpful and Has solve the problem 90%, the Price should repeat for all the Months/date as Show cased in Img 2.
    I have tried to use AllExcept funtion and All funtion to avoid the Date filter But no Luck.

     

    Img 1

    Img 2 

     

    • v-yueyunzh-msft's avatar
      v-yueyunzh-msft
      Community Support

      Hi , Anonymous 

      Thanks for your quick response !

      According to your description, you want to show all in your table .

      You can try to use this dax code:

      Measure = var _slicer = MIN('Calendar'[Date])
      var _material= MAX('Table'[Material])
      var _has_value =MAXX( FILTER(ALLSELECTED('Table') , 'Table'[Date]=_slicer && 'Table'[Material]=_material) , [Sales Price])
      var _no_value_date = MINX(  FILTER(ALLSELECTED('Table') , 'Table'[Date]>_slicer  && 'Table'[Material]=_material) , [Date])
      var _no_value =MAXX( FILTER(ALLSELECTED('Table') , 'Table'[Date] = _no_value_date  && 'Table'[Material]=_material) , [Sales Price])
      return
      IF(_has_value=BLANK(),_no_value,_has_value)

       

      Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

       

      Best Regards,

      Aniya Zhang

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