Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Calculated Column With Multiple LookupValue Filters

I have two types of calculated columns I need to create that are essentially lookup values with multiple criteria. I will need 3 of one and 3 of the other type.

 

The first type looks up a value in a related table based on its ID number and the date. This table has the data set up as follows:

 

IDDateOff?Hours RanAccuracy
110/1/201901292%
1

11/1/2019

1058%
112/1/20191052%
210/1/201901100%
2

11/1/2019

0398%
212/1/20190785%
310/1/20191034%
3

11/1/2019

0375%
312/1/201901100%

 

I'm trying to reference this table via calculated columns in a related table that also has Date and ID. Trying to return essentially the value in one of the other three columns based on Date and ID criteria. I know I'm close based on the CALCULATE(FILTER()) combination, but essentially I'm trying to do this in the other table:

 

Device Off =IF(

CALCULATE(

COUNTROWS(Table[Id]),

FILTER(Table,

Table[Id] = OtherTable[Id]

Table[Date] = OtherTable[Date],

Table[Off] = 1)) > 0, "Off", "On")

 

Accuracy = IF(

CALCULATE(

COUNTROWS(Table[Id]),

FILTER(Table,

Table[Id] = OtherTable[Id],

Table[Date] = OtherTable[Date],

Table[Accuracy] < .9)) > 0, "Low Accuracy", "")

 

Low Hours = IF(

CALCULATE(

COUNTROWS(Table[Id]),

FILTER(Table,

Table[Id] = OtherTable[Id],

Table[Date] = OtherTable[Date],

Table[Hours Ran] < 2)) > 0, "Low", "Normal")

 

The second calculated column is based on a string capture based on ID and Date. If the alert matches the month of the date, I want it to return the alert. Alert table:

 

IDDateAlertMajor AlertCritical Alert
110/20/2019Alert  
211/2/2019Alert Critical
212/14/2019 Major 
311/25/2019Alert Critical
312/13/2019Alert  

 

Each one of these alerts is returned the same way:

 

Alert = IF(

CALCULATE(

COUNTROWS(AlertTable[Id]),

FILTER(AlertTable,

AlertTable[Id] = OtherTable[Id],

MONTH(AlertTable[Date]) = (MONTH(OtherTable[Date]),

AlertTable[Alert] = "Alert")) > 0, "Alerts", "")

 

Major Alerts= IF(

CALCULATE(

COUNTROWS(AlertTable[Id]),

FILTER(AlertTable,

AlertTable[Id] = OtherTable[Id],

MONTH(AlertTable[Date]) = (MONTH(OtherTable[Date])

AlertTable[Alert] = "Major")) > 0, "Alerts - Major", "")

 

Critical Alerts= IF(

CALCULATE(

COUNTROWS(AlertTable[Id]),

FILTER(AlertTable,

AlertTable[Id] = OtherTable[Id]

MONTH(AlertTable[Date]) = (MONTH(OtherTable[Date])

AlertTable[Alert] = "Critical")) > 0, "Alerts - Critical", "")

 

The desired result would be something like this:

 

IDDateDevice OffLow HoursAccuracyAlertsMajor AlertsCritical Alerts

1

10/1/2019OnNormal Alerts  
111/1/2019OffLowLow Accuracy   
112/1/2019OffLowLow Accuracy   
210/1/2019OnLow    
211/1/2019OnNormal Alerts Alerts - Critical
212/1/2019OnNormalLow Accuracy Alerts - Major 
310/1/2019OffLowLow Accuracy   
311/1/2019OnNormalLow Accuracy   
312/1/2019OnLow Alerts  

 

I tried the CALCULATE(FILTER()) combinations for each one but I'm not getting that return on my OtherTable. Is there something I'm missing with the filter? Should something other than COUNTROWS() be used since I only need a single value for comparison? Feel like I'm almost there but just need that last bit to make it work out.

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Please check if this is what you want:

calculated columns.PNG

 

1. Create OtherTable.

OtherTable = SELECTCOLUMNS ( 'Table', "ID", [ID], "Date", [Date] )

 

2. Create Calculated columns.

Device Off = 
IF (
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            'Table',
            'Table'[ID] = OtherTable[ID]
                && 'Table'[Date] = OtherTable[Date]
                && 'Table'[Off] = 1
        )
    ) > 0,
    "Off",
    "On"
)
Low Hours = 
IF (
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            'Table',
            'Table'[ID] = OtherTable[ID]
                && 'Table'[Date] = OtherTable[Date]
                && 'Table'[Hours Ran] < 2
        )
    ) > 0,
    "Low",
    "Normal"
)
Accuracy = 
IF (
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            'Table',
            'Table'[ID] = OtherTable[ID]
                && 'Table'[Date] = OtherTable[Date]
                && 'Table'[Accuracy] < .9
        )
    ) > 0,
    "Low Accuracy",
    ""
)
Alert = 
IF (
    CALCULATE (
        COUNTROWS ( AlertTable ),
        FILTER (
            AlertTable,
            AlertTable[ID] = OtherTable[ID]
                && MONTH ( AlertTable[Date] ) = MONTH ( OtherTable[Date] )
                && AlertTable[Alert] = "Alert"
        )
    ) > 0,
    "Alerts",
    ""
)
Major Alerts = 
IF (
    CALCULATE (
        COUNTROWS ( AlertTable ),
        FILTER (
            AlertTable,
            AlertTable[ID] = OtherTable[ID]
                && MONTH ( AlertTable[Date] ) = MONTH ( OtherTable[Date] )
                && AlertTable[Major Alert] = "Major"
        )
    ) > 0,
    "Alerts - Major",
    ""
)
Critical Alerts = 
IF (
    CALCULATE (
        COUNTROWS ( AlertTable ),
        FILTER (
            AlertTable,
            AlertTable[ID] = OtherTable[ID]
                && MONTH ( AlertTable[Date] ) = MONTH ( OtherTable[Date] )
                && AlertTable[Critical Alert] = "Critical"
        )
    ) > 0,
    "Alerts - Critical",
    ""
)

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Please check if this is what you want:

calculated columns.PNG

 

1. Create OtherTable.

OtherTable = SELECTCOLUMNS ( 'Table', "ID", [ID], "Date", [Date] )

 

2. Create Calculated columns.

Device Off = 
IF (
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            'Table',
            'Table'[ID] = OtherTable[ID]
                && 'Table'[Date] = OtherTable[Date]
                && 'Table'[Off] = 1
        )
    ) > 0,
    "Off",
    "On"
)
Low Hours = 
IF (
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            'Table',
            'Table'[ID] = OtherTable[ID]
                && 'Table'[Date] = OtherTable[Date]
                && 'Table'[Hours Ran] < 2
        )
    ) > 0,
    "Low",
    "Normal"
)
Accuracy = 
IF (
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            'Table',
            'Table'[ID] = OtherTable[ID]
                && 'Table'[Date] = OtherTable[Date]
                && 'Table'[Accuracy] < .9
        )
    ) > 0,
    "Low Accuracy",
    ""
)
Alert = 
IF (
    CALCULATE (
        COUNTROWS ( AlertTable ),
        FILTER (
            AlertTable,
            AlertTable[ID] = OtherTable[ID]
                && MONTH ( AlertTable[Date] ) = MONTH ( OtherTable[Date] )
                && AlertTable[Alert] = "Alert"
        )
    ) > 0,
    "Alerts",
    ""
)
Major Alerts = 
IF (
    CALCULATE (
        COUNTROWS ( AlertTable ),
        FILTER (
            AlertTable,
            AlertTable[ID] = OtherTable[ID]
                && MONTH ( AlertTable[Date] ) = MONTH ( OtherTable[Date] )
                && AlertTable[Major Alert] = "Major"
        )
    ) > 0,
    "Alerts - Major",
    ""
)
Critical Alerts = 
IF (
    CALCULATE (
        COUNTROWS ( AlertTable ),
        FILTER (
            AlertTable,
            AlertTable[ID] = OtherTable[ID]
                && MONTH ( AlertTable[Date] ) = MONTH ( OtherTable[Date] )
                && AlertTable[Critical Alert] = "Critical"
        )
    ) > 0,
    "Alerts - Critical",
    ""
)

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thanks, Icey! One thing I also realized that was giving me trouble was the ID fields in each table weren't named the same, so when I referred to them in my formulas, it kept giving me either all or nothing there. It's amazing what a typo can do. Appreciate it!

Icey
Community Support
Community Support

Hi @Anonymous ,

 

I don't quite understand it. Please give me some screenshots to help me know your issue.

 

My understanding is like this, but it's no different.

OO.PNG

 

Best Regards,

Icey

Greg_Deckler
Community Champion
Community Champion

For the first one, you might look at using an "X" aggregation like MAXX, SUMX, etc. over a FILTER of RELATEDTABLE. 

 

for the second one, you should likely look at LOOKUPVALUE.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors