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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
NilR
Post Patron
Post Patron

DAX Max Function with multiple conditions

Question to answer: If John in zip code group 0 between 202001 and 202004 has ever voted?

 

Capture3.JPG

This is how I would right in sql but i need a measure in DAX to use the Y or N result in another measure:

 

MAX(CASE MEMBER='JOHN' AND VOTE='Y' THEN 'Y' ELSE 'N')

 

this is what I tireid but i get error "Cannot convert value sd014 of type text to type true/false"

 

VAR _MAX= IF
(
	MAXX
	(FILTER('TBL',
        [MEMBER]= "JOHN" && [VOTE]="Y" && [DATE] >= MIN_DATE && [DATE]  <= _MAX_DATE),
         [ZIP]),
        "YES"
        , "NO")

VAR _VOTE_MBRS = CALCULATE(SUM('TBL'[MBRS]),FILTER('TBL',([DATE] >= MIN_DATE && [DATE]  <= MAX_DATE) && _MAX = "YES"))

VAR _MBRS = CALCULATE(SUM('TBL'[MBRS]),FILTER('TBL',([DATE] >= MIN_DATE && [DATE]  <= MAX_DATE)))

RETURN
SWITCH (
    SELECTEDVALUE ( 'TBL'[MBRS] ),
    "JOHN", _VOTE_MBRS ,
     _MBRS
) 

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

HI @NilR,

You can try to use follow measure formula to get the count of vote rows based on the current 'zip' and 'member' group of a specific year range:

measure =
VAR voteCount =
    CALCULATE (
        COUNTROWS ( Table ),
        FILTER (
            ALLSELECTED ( Table ),
            [Vote] = "Y"
                && AND ( [INC Year] >= 202001, [INC Year] <= 202004 )
        ),
        VALUES ( Table[Zip_Code] ),
        VALUE ( Table[Member] )
    )
RETURN
    IF ( voteCount > 0, "Y", "N" )

Regards,

Xiaoxin Sheng

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

HI @NilR,

You can try to use follow measure formula to get the count of vote rows based on the current 'zip' and 'member' group of a specific year range:

measure =
VAR voteCount =
    CALCULATE (
        COUNTROWS ( Table ),
        FILTER (
            ALLSELECTED ( Table ),
            [Vote] = "Y"
                && AND ( [INC Year] >= 202001, [INC Year] <= 202004 )
        ),
        VALUES ( Table[Zip_Code] ),
        VALUE ( Table[Member] )
    )
RETURN
    IF ( voteCount > 0, "Y", "N" )

Regards,

Xiaoxin Sheng

amitchandak
Super User
Super User

@NilR , Assume you have selected a duration in slicer a measure can help

Calculate(count(Table[Memeber]), filter(allselected(Table), Table[VOTE] ="Y" && Table[MEMBER] = max(Table[MEMBER])))

 

vote in selected duration

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thank you! I need the Y and No result for another measure to use. this doesn't work for me.

@NilR , Not very clear

 

but this will give Y

if(not(isblank( Calculate(count(Table[Memeber]), filter(allselected(Table), Table[VOTE] ="Y" && Table[MEMBER] = max(Table[MEMBER]))) )) , "Y", Blank())

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thank you! I just updated my question with what I have tried and is not working .

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.