Forum Discussion

DarioH's avatar
DarioH
Regular Visitor
2 years ago

Having Issues using Calculate function, seems to be a problem with the PLACEHOLDER

Hi everyone, I am having issues with the function CALCULATE(), the logic seems obvious to me and it looks like it should work, I am not sure what is the problem, if you have any idea please give me a hand.

 

Let me give you more context. I have the column Issue_Report[Issues], and also have other colum that makes reference to the model year of the vehicle named Issue_Report[MY], this column contains either singles values such as "2021", "2022" or grouped values "2022; 2023", I have added manually another column that contains only the single values of the years named MODEL_YEAR_SELECTOR[MY_Selector] and I put this in a filter.

 

I need to create a measure that filter the Issues where the selected value in the MY_Selector (filter) is contained in the MY. The first thing I did was create a measure that indicates with 1 or 0 if the MY_Selector is contained in the MY:

 

Contains_MY =
IF(CONTAINSSTRING(SELECTEDVALUE(Issue_Report[MY]), SELECTEDVALUE(MODEL_YEAR_SELECTOR[MY_Selector])) = TRUE(), 1, 0)
 
This one works fine as it shows 1 when the MY matches the MY_selector, then I am using the function CALCULATE this way: 
 
Issue by MY_ =
CALCULATE(
    VALUES(Issue_Report[Issue]),
    Issue_Report[Contains_MY] = 1
)
 
I am getting the next error message: A function 'PLACEHOLDER' has been used in a True/False expression that is used as a table filter expression. This is not allowed.

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    I don't think measures (Contains_MY) can be used that way as a filter. have you tried implementing your measure's logic into a filter function of your calculate measure like so:

    Issue by MY_ =
    CALCULATE(
        VALUES(Issue_Report[Issue]),
        FILTER(
            ALL(Issue_Report), 
            IF(
                CONTAINSSTRING(
                    SELECTEDVALUE(Issue_Report[MY]), 
                    SELECTEDVALUE(MODEL_YEAR_SELECTOR[MY_Selector])
                ) = TRUE(), 1, 0
            ) = 1
        )
    )

     careful with the all, i'm not quite sure if there's filter context in your issue_report table that you needed.

  • DarioH's avatar
    DarioH
    Regular Visitor

    Hi Corey, first thing, thanks for your support. Please see the image attached. On left side you can see the result I am trying to get, that table shows [Issues], [MY] and the measure [Contains], with an specific filter (on that visual) that only displays values where Contains = 1.  You can see that I have selected MY= 2019 on the filter [MY_Sel]

     

    In the table on the right side I added the measure you suggested [Issue by MY_] and the MY, the error message says: "A table of multiple values was supplied, where a single value was expected" I tried with and without the ALL(). Do you know what can be causing this error?

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Could you share more information about what the end goal is?

       

      The issue is in using Values as it can return a table (with multiple values) when you add it to the visual it expects a single value. but if your end goal is to say count the number of issues by model year like this:

      The measure works fine by just switching to countrows to get a single numeric value.

      edit: to clarify I guess I am confused on how you expect the table on the right should differ from the table on the left when working.