Search code examples
powerbidaxpowerbi-desktop

PowerBi Calculated column not bringing over correct counts


I have two tables. I want to add a calculated column that counts the amount of orders completed by month. The Year-Month column has been brought over through a summarize calculation so it's the same data that I'm trying to reference in the original table. Yet, the calculated column is only entered a number for items with no date.

enter image description here

This is the formula I used for my calculated column:

Column = CALCULATE(
    SUM(Renewed[Complete Count]),
    FILTER(ALLSELECTED(Renewed[Year-Month]), Renewed[Year-Month] = SELECTEDVALUE(Closed[Year-Month]))
  )

I validated that both columns in the tables are formatted as below. What could be causing the issue of not populating?

enter image description here


Solution

  • SELECTEDVALUE needs to be in a CALCULATE when in used in Calculated Columns, however you don't need SELECTEDVALUE in Calculated Columns.

    Try:

    Column = 
      var thisYM = [Year-Month]
      RETURN CALCULATE(
        SUM(Renewed[Complete Count]),
        FILTER(ALLSELECTED(Renewed[Year-Month]), Renewed[Year-Month] = thisYM)
      )
    

    You could also update your Closed table to include this from the get-go. Try:

    Closed = SUMMARIZE(
        'Renewed',
        'Renewed'[Year-Month],
        "Total", SUM('Renewed'[Complete Count])
      )