Forum Discussion

cruzp's avatar
cruzp
Icon for Helper V rankHelper V
3 years ago
Solved

Create a measure/column that gets the category value based on the selected date

 

I have a data like this in Power BI:

 

PROJECT_BKPROJECT_NAMEREVENUE_CATEGORY_BKSNAPSHOT_DATE_BK
PROJ-0021POC - Cloud RC_PS_TM07/12/2022
PROJ-0021POC - Cloud RC_PS_TM08/12/2022
PROJ-0021POC - Cloud RC_PS_TM13/11/2022
PROJ-0021POC - Cloud RC_DX_EF14/10/2022
PROJ-0021POC - Cloud RC_DX_EF15/10/2022
PROJ-0021POC - Cloud RC_DX_EF20/09/2022
PROJ-0021POC - Cloud RC_DX_EF21/09/2022
PROJ-11113DL - TokenizedDB_TD_ER23/12/2022
PROJ-11113DL - TokenizedDB_TD_ER01/12/2022

 

What I want to have are the ff:

  • A single dropdown date that contains only the values that is existing in the SNAPSHOT_DATE_BK
  • A calculated field called 'CURRENT_REVENUE_CATEGORY_BK' that shows the associated value based on what is selected on the single dropdown date

 

Expected Output Sample 1: 

 

Assuming that the single dropdown date is selected to 08/12/2022

The SELECTED_DATE_REVENUE_CATEGORY_BK field should have a value of:

  • 'RC_PS_TM' for PROJ-0021 since that is the associated REVENUE_CATEGORY_BK on 08/12/2022 for that specific project
  • Null for PROJ-1111 since it does not have a REVENUE_CATEGORY_BK on 08/12/2022

 

 

Expected Output Sample 2:

Assuming that the single dropdown date is selected to 23/12/2022

The SELECTED_DATE_REVENUE_CATEGORY_BK field should have a value of:

  • Null for PROJ-0021 since it does not have a REVENUE_CATEGORY_BK on 23/12/2022
  • 'DB_TD_ER' for PROJ-1111 since that is the associated REVENUE_CATEGORY_BK on 23/12/2022 for that specific project.

 

 

Kindly help  me please...

 

  • Hi , cruzp 

    Thanks for your sample data !

    According to your description, you want to "Create a measure/column that gets the category value based on the selected date".

    Here are the steps you can refer to :
    (1)We need to click "New Table" to create a dimension table  as the date slicer:

    Date = VALUES('Table'[SNAPSHOT_DATE_BK])

     

    (2)Then we can create a measure like this:

    SELECTED_DATE_REVENUE_CATEGORY_BK = CALCULATE( MAX('Table'[REVENUE_CATEGORY_BK])  , 'Table'[SNAPSHOT_DATE_BK]= MAX('Date'[SNAPSHOT_DATE_BK]))

     

    (3)Then we can put the fields on the visual and we can get the result as follows:

     

     

     

     

    If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem. (You can also upload you sample .pbix [without sensitive data] to the OneDrive and share with the OneDrive link to me ! )

    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 , cruzp 

    Thanks for your sample data !

    According to your description, you want to "Create a measure/column that gets the category value based on the selected date".

    Here are the steps you can refer to :
    (1)We need to click "New Table" to create a dimension table  as the date slicer:

    Date = VALUES('Table'[SNAPSHOT_DATE_BK])

     

    (2)Then we can create a measure like this:

    SELECTED_DATE_REVENUE_CATEGORY_BK = CALCULATE( MAX('Table'[REVENUE_CATEGORY_BK])  , 'Table'[SNAPSHOT_DATE_BK]= MAX('Date'[SNAPSHOT_DATE_BK]))

     

    (3)Then we can put the fields on the visual and we can get the result as follows:

     

     

     

     

    If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem. (You can also upload you sample .pbix [without sensitive data] to the OneDrive and share with the OneDrive link to me ! )

    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

     

    • cruzp's avatar
      cruzp
      Icon for Helper V rankHelper V

      HI v-yueyunzh-msft this seems to work. how about for another field which for example the "Current Stage"
      Parameters should be included in the measure:
      [Stage Bk] = 'R4' 
      [Stage Bk] = 'R5'

      Current_Stage = 
          CALCULATE( MAX(DIM_STAGE[STAGE_BK]), 
          'Table'[SNAPSHOT_DATE_BK]= MAX('Date'[SNAPSHOT_DATE_BK]))
          )
      

       how do i add the parameters in the formula?