Reply
EltonjohnWick
Frequent Visitor

Userelationship for multiple dates

Hi 

 

I have this dax that works for filtering lending to drawn on a table. 

 

Drawn Deals =
CALCULATE(
COUNTROWS(Lending), -- Or any other aggregation you'd like
USERELATIONSHIP(Lending[Drawn Date], DateHierarchy[Date]),
DateHierarchy[WeekNum] = SELECTEDVALUE(DateHierarchy[WeekNum])
)

  •  

What I need is a combined code that also looks at lead, approved and declined. These stages have a slicer to flip between them, which I need to trigger to the lookup on the relevant date ie if column stage slicer is lead then look at lead date, if slicer is approved look at approved date. The slicer is a week output but it's linked to date table to pull the week though. Lead is the active relationship to the date table while the others are inactive linked to the date table.

 

  •  

Thanks 

 

1 ACCEPTED SOLUTION
v-kongfanf-msft
Community Support
Community Support

Hi @EltonjohnWick ,

 

You need create stage column as table slicer and then try to create formula like below:

vkongfanfmsft_0-1731650834399.png

vkongfanfmsft_2-1731650906054.png

Drawn Deals1 =
VAR SelectedStage =
    SELECTEDVALUE ( StageSlicer[Stage] )
RETURN
    SWITCH (
        TRUE (),
        SelectedStage = "Lead",
            CALCULATE (
                COUNTROWS ( Lending ),
                TREATAS ( VALUES ( DateHierarchy[Date] ), Lending[Lead Date] ),
                DateHierarchy[WeekNum] = SELECTEDVALUE ( DateHierarchy[WeekNum] )
            ),
        SelectedStage = "Approved",
            CALCULATE (
                COUNTROWS ( Lending ),
                TREATAS ( VALUES ( DateHierarchy[Date] ), Lending[Approved Date] ),
                DateHierarchy[WeekNum] = SELECTEDVALUE ( DateHierarchy[WeekNum] )
            ),
        SelectedStage = "Declined",
            CALCULATE (
                COUNTROWS ( Lending ),
                TREATAS ( VALUES ( DateHierarchy[Date] ), Lending[Declined Date] ),
                DateHierarchy[WeekNum] = SELECTEDVALUE ( DateHierarchy[WeekNum] )
            ),
        CALCULATE (
            COUNTROWS ( Lending ),
            TREATAS ( VALUES ( DateHierarchy[Date] ), Lending[Drawn Date] ),
            DateHierarchy[WeekNum] = SELECTEDVALUE ( DateHierarchy[WeekNum] )
        )
    )

vkongfanfmsft_1-1731650889650.png

 

Best Regards,
Adamk Kong

 

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

5 REPLIES 5
EltonjohnWick
Frequent Visitor

Thank you so much. 

 

Finally works and saves me the visual clutter of having two different date slicer.

 

Much appreciated

v-kongfanf-msft
Community Support
Community Support

Hi @EltonjohnWick ,

 

You need create stage column as table slicer and then try to create formula like below:

vkongfanfmsft_0-1731650834399.png

vkongfanfmsft_2-1731650906054.png

Drawn Deals1 =
VAR SelectedStage =
    SELECTEDVALUE ( StageSlicer[Stage] )
RETURN
    SWITCH (
        TRUE (),
        SelectedStage = "Lead",
            CALCULATE (
                COUNTROWS ( Lending ),
                TREATAS ( VALUES ( DateHierarchy[Date] ), Lending[Lead Date] ),
                DateHierarchy[WeekNum] = SELECTEDVALUE ( DateHierarchy[WeekNum] )
            ),
        SelectedStage = "Approved",
            CALCULATE (
                COUNTROWS ( Lending ),
                TREATAS ( VALUES ( DateHierarchy[Date] ), Lending[Approved Date] ),
                DateHierarchy[WeekNum] = SELECTEDVALUE ( DateHierarchy[WeekNum] )
            ),
        SelectedStage = "Declined",
            CALCULATE (
                COUNTROWS ( Lending ),
                TREATAS ( VALUES ( DateHierarchy[Date] ), Lending[Declined Date] ),
                DateHierarchy[WeekNum] = SELECTEDVALUE ( DateHierarchy[WeekNum] )
            ),
        CALCULATE (
            COUNTROWS ( Lending ),
            TREATAS ( VALUES ( DateHierarchy[Date] ), Lending[Drawn Date] ),
            DateHierarchy[WeekNum] = SELECTEDVALUE ( DateHierarchy[WeekNum] )
        )
    )

vkongfanfmsft_1-1731650889650.png

 

Best Regards,
Adamk Kong

 

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

johnt75
Super User
Super User

This seems like a perfect use case for a calculation group. Create a base measure as

Num deals = COUNTROWS( Lending )

and then create a calculation group with items like

Lead Deals = SELECTEDMEASURE()

Drawn Deals =
CALCULATE (
    SELECTEDMEASURE(),
    -- Or any other aggregation you'd like
    USERELATIONSHIP ( Lending[Drawn Date], DateHierarchy[Date] )
)

You don't need to manipulate the relationship for the Lead calculation item because that relationship is already active. And you don't need the SELECTEDVALUE as that filter is already being applied.

Sahir_Maharaj
Super User
Super User

Hello @EltonjohnWick,

 

Can you please try the following approach:

 

Drawn Deals =
VAR SelectedStage = SELECTEDVALUE(StageSlicer[Stage])
RETURN
    SWITCH(
        SelectedStage,
        
        "Lead",
        CALCULATE(
            COUNTROWS(Lending),
            DateHierarchy[WeekNum] = SELECTEDVALUE(DateHierarchy[WeekNum])
        ),
        
        "Approved",
        CALCULATE(
            COUNTROWS(Lending),
            USERELATIONSHIP(Lending[Approved Date], DateHierarchy[Date]),
            DateHierarchy[WeekNum] = SELECTEDVALUE(DateHierarchy[WeekNum])
        ),
        
        "Declined",
        CALCULATE(
            COUNTROWS(Lending),
            USERELATIONSHIP(Lending[Declined Date], DateHierarchy[Date]),
            DateHierarchy[WeekNum] = SELECTEDVALUE(DateHierarchy[WeekNum])
        ),
        
        "Drawn",
        CALCULATE(
            COUNTROWS(Lending),
            USERELATIONSHIP(Lending[Drawn Date], DateHierarchy[Date]),
            DateHierarchy[WeekNum] = SELECTEDVALUE(DateHierarchy[WeekNum])
        ),
        
        BLANK()
    )

 


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Hi 

 

Thanks for sending on, however this didn't work. I can see the stage options available for the relevant week but the table is blank when I add the measure 

avatar user

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)