Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Filter out values from Measure Iteration

I have a measure that is almost working... I'm stuck on not being able to filter out values that don't match certain criteria.

 

I'll outline the logic first, then post my current measure:

  1. For a given site
  2. For a specific project
  3. Where CareServices = True
  4. And Gross Program > 0
  5. AVERAGEX [% of Program Category]

Measure Logic

 

As you can see, where the context strictly meets the criteria (Project 2) the measure currently works, but where the criteria are not strictly met, I don't get the "correct" answer.

 

Here is the current measure:

% Cat Avg = 
CALCULATE(
AVERAGEX(
prog_SiteAll,
[% of Program Category]
),
ALLEXCEPT(prog_SiteAll, site_Sites[Abbreviated Name], prog_SiteAll[Project Name]),
FILTER(prog_SiteAll, prog_SiteAll[Gross Program Area] > 0) // I don't think this line is currently doing much, if anything... at least nothing useful.
)

Thanks very much for looking! Spent serveral hours today watching videos and trying to better wrap my head around Evaluations and Filter Contexts particularly when you're in a measure, and I'm stuck!

  • Anonymous's avatar
    Anonymous
    6 years ago

    mahoneypat thanks for trying to assist and being friendly about it! Since it needed it anyhow I did rebuild the data model and made a few small tweaks. I think though it should've still been able to work in the old data model. The final Measure looks like this, the use of "Values" was the keystone, ironically tripped myslef up on the conditional operators when manually cross checking the mathematical results (oh well):

     

    Avg Cat Deviation Value = 
    VAR __Calc = //create a virtual table that filters to the context of the current row; Site, Project, and associate Space Categories that are Care Services. Include the caluclated measures for the % of Benchmark Program and the previous % of Benchmark Program
    CALCULATETABLE(
    ADDCOLUMNS(
    SUMMARIZE( 'prog Proposed Project Program', Sites[Abbreviated Name], 'prog Projects'[ID], 'prog Space Categories'[ID] ),
    "% of Bnch", [Program % of Cat Benchmark Prog], "Prev %", [Prev % Bnch]
    ),
    ALL('prog Proposed Project Program'), //get all rows from this table
    VALUES(Sites[Abbreviated Name]), //filter to the Site context of current row
    VALUES('prog Projects'[Project Name]), //filter to the Project context of current row
    'prog Proposed Project Program'[Program Area] > 0, //filter for only categories that have changed in this project
    'prog Space Categories'[CareServices] = TRUE() // filter for Space Categories that are only marked as "Care Services"
    )

    VAR AVGBnch = AVERAGEX( __Calc, [% of Bnch]) //calculate the Average of the rows in the filtered table
    VAR AVGPrev = AVERAGEX( __Calc, [Prev %]) //calculate the Average of the rows in the filtered table
    VAR PercRemainder = (AVGBnch - AVGPrev)
    RETURN
    PercRemainder

     

12 Replies

  • mahoneypat's avatar
    mahoneypat
    Microsoft Employee

    Try this measure instead:

     

    NewMeasure = calculate(averagex(values(prog_SiteAll[Project Name]), [% of Program Quantity]), prog_SiteAll[CareServices] = "True", Filter(All(prog_SiteAll[Gross Program]), prog_SiteAll[Gross Program]>0))

     

    If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

    Regards,

    Pat

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      mahoneypat thanks for trying, but that did not work either. The filtering clearly works, but I end up with the row value in the Measure. So for the ambulator row where the % of Program Category is 50.85% the result in the measure is the same value. Rows that don't meet the logic criteria show blank, so that is "good" in the sense that the logic is working, but not in the context of row that are not compliant, which means it is not getting out of the row context to iterate over multiple values.

       

      In a previous iteration I had gone down the road of a virtual table, which I believe may still be where the solution lies, so I may try applying what you gave me to a virtual table, and see if that propegates as expected. Below is the code as I wrote it, there are a couple of relationships not readily apparent in my original post, though I don't think they have any bearing on the performance of this particular measure.

       

      Measure = 
      CALCULATE(
      AVERAGEX(
      VALUES(
      prog_SiteAll[Project Name]
      ),
      [% of Program Category]
      ),
      prog_Categories[CareServices] = TRUE(),
      FILTER(
      ALL(prog_SiteAll[Gross Program Area]),
      prog_SiteAll[Gross Program Area] > 0
      )
      )

      Thanks for trying!

      • mahoneypat's avatar
        mahoneypat
        Microsoft Employee

        Reread your post. Instead of iterate over Program Name, inside the Values() of my proposed measure try the Cat column instead.

         

        If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

        Regards,

        Pat

    • Anonymous's avatar
      Anonymous
      Not applicable

      mahoneypat thanks for trying to assist and being friendly about it! Since it needed it anyhow I did rebuild the data model and made a few small tweaks. I think though it should've still been able to work in the old data model. The final Measure looks like this, the use of "Values" was the keystone, ironically tripped myslef up on the conditional operators when manually cross checking the mathematical results (oh well):

       

      Avg Cat Deviation Value = 
      VAR __Calc = //create a virtual table that filters to the context of the current row; Site, Project, and associate Space Categories that are Care Services. Include the caluclated measures for the % of Benchmark Program and the previous % of Benchmark Program
      CALCULATETABLE(
      ADDCOLUMNS(
      SUMMARIZE( 'prog Proposed Project Program', Sites[Abbreviated Name], 'prog Projects'[ID], 'prog Space Categories'[ID] ),
      "% of Bnch", [Program % of Cat Benchmark Prog], "Prev %", [Prev % Bnch]
      ),
      ALL('prog Proposed Project Program'), //get all rows from this table
      VALUES(Sites[Abbreviated Name]), //filter to the Site context of current row
      VALUES('prog Projects'[Project Name]), //filter to the Project context of current row
      'prog Proposed Project Program'[Program Area] > 0, //filter for only categories that have changed in this project
      'prog Space Categories'[CareServices] = TRUE() // filter for Space Categories that are only marked as "Care Services"
      )

      VAR AVGBnch = AVERAGEX( __Calc, [% of Bnch]) //calculate the Average of the rows in the filtered table
      VAR AVGPrev = AVERAGEX( __Calc, [Prev %]) //calculate the Average of the rows in the filtered table
      VAR PercRemainder = (AVGBnch - AVGPrev)
      RETURN
      PercRemainder