Forum Discussion

zervino's avatar
zervino
Icon for Helper I rankHelper I
1 year ago
Solved

Delta between values of same column but different rows

I have a table like this:

 

PlanMonthCustomerSales
Budget5ABC100
Actuals5ABC50
Forecast5ABC130

 

I want to create a measure that compares always against the "Actuals" of the same month and customer:

 

PlanMonthCustomerSalesvs Actuals
Budget5ABC10050
Actuals5ABC500
Forecast5ABC13080

 

How can I achieve this?

 

Thanks

  • zervino Try:

    vs Actuals Measure = 
      VAR __Sales = MAX( 'Table'[Sales] )
      VAR __Actuals = MAXX( FILTER( ALL( 'Table', [Plan] = "Actuals" ), [Sales] )
      VAR __Result = __Sales - __Actuals
    RETURN
      __Result
  • lbendlin's avatar
    lbendlin
    1 year ago

    Ooh, look, a Calculate 🙂

     

    vs Actuals = sum('Table'[Sales])-CALCULATE(sum('Table'[Sales]),'Table'[Plan]="Actuals")
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi zervino,

    Thank you  for reaching out to the Microsoft fabric community forum.
    Thank you lbendlin, for you reply regarding the issue.

    By creating this Dax measure you may achieve :

    vs Actuals = 
    VAR currentMonth = SELECTEDVALUE('SalesData'[Month])
    VAR currentCustomer = SELECTEDVALUE('SalesData'[Customer])
    VAR actualSales = 
        CALCULATE(
            SUM('SalesData'[Sales]),
            'SalesData'[Plan] = "Actuals",
            'SalesData'[Month] = currentMonth,
            'SalesData'[Customer] = currentCustomer
        )
    RETURN
    IF(SELECTEDVALUE('SalesData'[Plan]) = "Actuals", 0, SUM('SalesData'[Sales]) - actualSales)
    

    I tested it with  sample data, and it working fine. Please find the attached screenshot and Pbix for your reference.

    If the response has addressed your query, please Accept it as a solution and give a 'Kudos' so other members can easily find it

    Best Regards,
    Harshitha.

6 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity Champion

    zervino Try:

    vs Actuals Measure = 
      VAR __Sales = MAX( 'Table'[Sales] )
      VAR __Actuals = MAXX( FILTER( ALL( 'Table', [Plan] = "Actuals" ), [Sales] )
      VAR __Result = __Sales - __Actuals
    RETURN
      __Result
    • lbendlin's avatar
      lbendlin
      Icon for Super User rankSuper User

      Ooh, look, a Calculate 🙂

       

      vs Actuals = sum('Table'[Sales])-CALCULATE(sum('Table'[Sales]),'Table'[Plan]="Actuals")
  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi zervino,

    Thank you  for reaching out to the Microsoft fabric community forum.
    Thank you lbendlin, for you reply regarding the issue.

    By creating this Dax measure you may achieve :

    vs Actuals = 
    VAR currentMonth = SELECTEDVALUE('SalesData'[Month])
    VAR currentCustomer = SELECTEDVALUE('SalesData'[Customer])
    VAR actualSales = 
        CALCULATE(
            SUM('SalesData'[Sales]),
            'SalesData'[Plan] = "Actuals",
            'SalesData'[Month] = currentMonth,
            'SalesData'[Customer] = currentCustomer
        )
    RETURN
    IF(SELECTEDVALUE('SalesData'[Plan]) = "Actuals", 0, SUM('SalesData'[Sales]) - actualSales)
    

    I tested it with  sample data, and it working fine. Please find the attached screenshot and Pbix for your reference.

    If the response has addressed your query, please Accept it as a solution and give a 'Kudos' so other members can easily find it

    Best Regards,
    Harshitha.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi zervino,

      Just wanted to check if you had the opportunity to review the suggestion provided?

      If the response has addressed your query, please Accept it as a solution and give a 'Kudos' so other members can easily find it.

       

      Thank You.

      Harshitha.

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi zervino  ,

        I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please Accept it as a solution so that other community members can find it easily.


        Thank you.