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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
ndo03001
Frequent Visitor

LOOKUPVALUE and Nested IF

I have a database in DirectQuery where each row has a record of a specific course (COURSE: string) an individual (IND_ID: string) took in a particular period of time (YRTR). The courses have different levels (LVL). I want to mark the individual (IND_ID) as "Entry" if they took even one Entry course (D, D2 or D3) within a specific period of time (YRTR).  The purpose is to have a way of flagging someone as Entry at a point in time which can change from yrtr to yrtr so that I can use that as a base for some of my visuals.

EntryStdnt = IF(LOOKUPVALUE(TABLE1[LVL], TABLE1[YRTR], TABLE1[YRTR], TABLE1[IND_ID], TABLE1[IND_ID]) ="D" || "D2" || "D3", "Entry" ,"Upper")
I pieced together the measure above based on suggestions for similar problems noted on the community board. However when I use this formula I get the following error: A single value for column IND_ID and YRTR in TABLE1 cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifiying an aggregation such as min, max, count, or sum to get a single result.

Suggestions for next steps would be wonderful.

 

YRTRIND_IDCOURSESUBJCOU_NBRMOD_CODELVLREG_CRHR
Sp1900001631000621ESC108009L3
Sp1900001631001357PSA102003L3
F1900001631000252ENG095012D4
F1900001631000208STS102112L2
F1900001631000253ENG102012L4
F1900001631000221SOC108012L3
F1900001631000007QOM1051 L3
F1800001631000170PHI1035 L3
F1800001631000191PHI1020 L4
Sp1800004524000183QOM103112L3
Sp1800004524000364SOC103312L3
Sp1800004524000209PHI102012L4
F1800004524001136MAT0030 D25
F1800004524001510ENG009009D4
F1800004524001540ENG1021 L4
F1800004524000386PQB1031 L3
Sp1900004524001196ENG009009D4
Sp1900004524000456PSC1020 L4
Sp1900004524000689ENG1021 L4
3 REPLIES 3
Stachu
Community Champion
Community Champion

I took a slightly different approach here, counting the rows with level D,D2,D3 for a given year and id

EntryStdnt =
VAR __yrtr = TABLE1[YRTR]
VAR __ind_id = TABLE1[IND_ID]
VAR __relevant =
    FILTER (
        TABLE1,
        TABLE1[YRTR] = __yrtr
            && TABLE1[IND_ID] = __ind_id
            && ( TABLE1[LVL] = "D"
            || TABLE1[LVL] = "D2"
            || TABLE1[LVL] = "D3" )
    )
VAR __lvl =
    COUNTROWS ( __relevant )
RETURN
    IF ( __lvl > 0, "Entry", "Upper" )

is the result as you would expect it?



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

@StachuJust tried your suggestion (as a new column) and received an error that the function COUNTROWS is not allowed in DirectQuery models. When I try it as a new measure instead, I get the same error as the original poster (A single value...cannot be determined). Still looking for a solution on this.

this is the version without COUNTROWS

EntryStdnt = 
VAR __yrtr = TABLE1[YRTR]
VAR __ind_id = TABLE1[IND_ID]
VAR __relevant = FILTER(TABLE1,TABLE1[YRTR]=__yrtr&&TABLE1[IND_ID]=__ind_id && (TABLE1[LVL]="D" || TABLE1[LVL]="D2" ||TABLE1[LVL]="D3"))
VAR __lvl = CALCULATE(MIN('TABLE1'[LVL]),__relevant)
RETURN
IF(ISBLANK(__lvl),"Upper","Entry")

but based on this reference

https://docs.microsoft.com/en-us/analysis-services/tabular-models/dax-formula-compatibility-in-direc...

you should now get error because of FILTER, as it's calculated column and not a measure. Can you test and confirm that's the case?

 

How do you plan to use the new column? if it's in the calculation only we could create a measure for it



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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