Forum Discussion

ndo03001's avatar
ndo03001
Frequent Visitor
6 years ago

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

  • Stachu's avatar
    Stachu
    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?

    • eosborn918's avatar
      eosborn918
      New Member

      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.