Forum Discussion

david_blabla's avatar
david_blabla
Frequent Visitor
4 years ago

Filter does not work on calculated column

Hi all,

 

I ran into a problem recently and hope that someone knows what I am doing wrong:

I have two data sets which are mapped by an ID.

The element dataset looks like this:

elementsummary_IDfinish dateelement type
a123.09.21Type 1
b122.09.21Type 2
c221.09.21...

Summary dataset looks like this:

IDSummary Finish Date (see below)
1...
2...

I am calculating the Summary Finish Date as the last finish date of all included elements using this formular:

 

 

Summary Finish Date = CALCULATE(
        MAX(element[finish date]),
        FILTER(element, element[summary_ID] = summary[ID]))

 

 

Afterwards I pulled in "ID" and "Summary Finish Date" both from the summary dataset into a table on a PowerBI dashboard. On the same dashboard I also included a filter by "element type" from the element dataset.

Unfortunately, that filter does not do anything for me. When I filter for Type 2 the displayed date will still be 23.09.21 for ID 1.

Only if I include the filter into the calculated column directly it works:

 

 

Summary Finish Date = CALCULATE(
        MAX(element[finish date]),
        FILTER(element, element[summary_ID] = summary[ID] && element[element type] = "Type 2"))

 

 

The result now is 22.09.21 - As expected.

Any idea what I have to do to get the variable filter to work?

 

Thanks,

David

6 Replies

    • david_blabla's avatar
      david_blabla
      Frequent Visitor

      Hi amitchandak, I can not believe that is true as on other pages I have pulled calculated columns into tables as well and the displayed data get's filtered based on the slicers.

      • amitchandak's avatar
        amitchandak
        Super User

        david_blabla , a measure can use slicer value. Not the column, that is what I know.  Can you share a sample pbix after removing sensitive data.

  • smpa01's avatar
    smpa01
    Community Champion

    david_blabla  if I understand it correctly,

     

    you created 'Summary Finish Date' calculated column in 'summary'

    and

    in your data model 'summary' filters 'element' in 1 to Many.

     

    In the viz, you brought all your AXIS (columns) from 'summary' and expects that Viz to be sliced by an element (element type) from 'element'.

     

    Since 'element' does not filter 'summary' that slicer would not work.

     

    In order to make it work,

    you can build an 'element type' table and connect it to 'element' 

    and

    write a measure 

    and

    bring your AXIS from both 'summary' and 'element type' table

    and 

    bring slicers from all the dimension tables ('summary','elemnt type')

     

     

     

    • david_blabla's avatar
      david_blabla
      Frequent Visitor

      Hi smpa01,

       


      smpa01 wrote:

      Since 'element' does not filter 'summary' that slicer would not work.

      That sounds very promising.

      Unfortunately, I did not understand your solution. Can you maybe elaborate a bit more?

       

      Thanks,

      David

      • smpa01's avatar
        smpa01
        Community Champion

        david_blabla  I am guessing your DM looks like this

         

         

        The flow of filter (arrow) is from summary to element, which means only columns from summary can slice anything from element, summary can slice summary. But element can't slice sumamry unless you make the filter bi-directional (which is not recommended) but then it introduces a lot of ambiguity in the model.

         

        What I have suggested is this. When building viz, bring all the axis and slicers from from 'elementType' and 'summary'; create a measure on 'element' and drop that on the axis.  Slicer can easily slice them.