Forum Discussion

JacobMotu's avatar
JacobMotu
Frequent Visitor
3 years ago
Solved

Conditional formatting table based on a target set

Hi community, This is my simplified data model:   Test pbix file: download Goal: I'm trying to highlight values in a report table (quite similar to table Results) that are bel...
  • JacobMotu's avatar
    JacobMotu
    3 years ago

    I already added the link for a testing pbix file into my original post yesterday, but forgot to mention it in the previous post.

    I use this formula that works for me now:

     

    MgCheck = 
    VAR MgMinCheckVar =
        SUMX(
            Targets,
            CALCULATE(
                SUM(Targets[MgMin]),
                Samples[TargetID] = EARLIER(Targets[TargetID])
            )
        )
    VAR MgMaxCheckVar =
        SUMX(
            Targets,
            CALCULATE(
                SUM(Targets[MgMax]),
                Samples[TargetID] = EARLIER(Targets[TargetID])
            )
        )
    RETURN
        SWITCH(
            TRUE(),
            Results[Mg] > MgMaxCheckVar, 1,
            Results[Mg] < MgMinCheckVar, -1,
            0
        )

     

     

    It is probably not the simpliest either the most efficient formula, but does the job. Also most of  the previous solutions work.

    The reason why it kept giving me all those errors was because there is only one relationship with the Target tables which is the one with Samples table, but the Cross filter direction was set to Single. Once I switched that to Both, it works. I noticed that only because everything was working in the test model where Both was selected by default. I hope it will not cause any issues in the future with other visuals. But because even in my real model there is only one relationship to Target table, there is no ambiguity.

    Thanks in advance for your reaction Theo. I hope you won't prove me wrong on this 🙂