Forum Discussion

Fanis_Georg's avatar
Fanis_Georg
Regular Visitor
1 year ago
Solved

Dynamic comparison of values

Hello team

 

I have a table that i have the costs of the materials for the full year broken down by month. Each month that I am running the results i add it in the same excel right under the previous month because the data is not too large and other users are also using it for their analysis. The data structure looks something like below. i want to create a matrix or a table where I compare the current period result vs STD and also the current vs the  Previous Period (CP-1). Obviously the current now is month 6, but then it will change to 7 and so on, that is why i have created this filtering under the column "Period" >> Current, CP-1, CP-2,........ Which is automtaicaly updated as we are progressing during the year. So i would need to have 4 calculated columns, 

1. to show current vs std

2. to show current preriod vs previous period

3. current vs standard percentage

4. Current vs previous period percentage.

 

Can you please help with the DAX

MaterialCosting ResultPeriod
1234561,511.22STD
1234561,444.64CP-3
1234561,444.64CP-2
1234561,444.64CP-1
1234561,434.44Current

 Thanks a lot

 

 

  • Fanis_Georg So perhaps something like this:

    Current vs. Standard = 
      VAR __Material = MAX( 'Table'[Material] )
      VAR __TableCurrent = FILTER( ALL( 'Table' ), [ResultPeriod] = "Current" )
      VAR __TableSTD = FILTER( ALL( 'Table' ), [ResultPeriod] = "STD" )
      VAR __Current = SUMX( __TableCurrent, [Costing] )
      VAR __STD = SUMX( __TableSTD, [Costing] )
      VAR __Result = __Current - __STD
    RETURN
      __Result
    

7 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Fanis_Georg So perhaps something like this:

    Current vs. Standard = 
      VAR __Material = MAX( 'Table'[Material] )
      VAR __TableCurrent = FILTER( ALL( 'Table' ), [ResultPeriod] = "Current" )
      VAR __TableSTD = FILTER( ALL( 'Table' ), [ResultPeriod] = "STD" )
      VAR __Current = SUMX( __TableCurrent, [Costing] )
      VAR __STD = SUMX( __TableSTD, [Costing] )
      VAR __Result = __Current - __STD
    RETURN
      __Result
    
    • Fanis_Georg's avatar
      Fanis_Georg
      Regular Visitor

      Greg_Deckler  your solution seems to be working but I come across another issue now. When I enter the calculate measure to my matrix i would expect a result like with 4 columns, CP-1, Current, STD, Current vs Standard. Instead i have the following, CP-1, Current vs Standard, Current, Current vs Standard, Standard, Current vs Standard. So basicaly the Current vs Standard calculated measure repeats after each and every column of the matrix.

  • Hi,

    Based on the table that you have shared, show the expected result very clearly.

  • Fanis_Georg 

    do you have date column or other column that will show different period of data? Otherwise how to know which one is the current one?

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

    Hi Fanis_Georg ,

    Thank you for reaching out to Microsoft Fabric Community.

    Thank you ryan_mayu Ashish_Mathur Greg_Deckler for the prompt response.

     

    I have created a PBIX file by using sample data to replicate the scenario.Please go through the attached PBIX file for your reference.

     

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

    Thank you.