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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Madhu155154
Regular Visitor

How to use USERELATIONSHIP with multiple Criteria to switch dates, when meeting the Criteria

 Any suggestion on how to achieve the below requirements:

 

I  have two tables,  one with 4 columns and another one is a calendar table 

 

Columns -> 

 

Created Date:

Loan Amount:

Approved date: 

Status: "Pending", " Under-Process", "Approved".

 

I have created a relationship between the Calender table and the main table :

 

 * active relation: created date  and Calendar date 

 * inactive relation: approved date and calendar date 

 

I want to sum up the loan amount when I use the date slicer ( date column from calendar table ) ->

 

for the status of Approved, it needs to use the Approved date column and for another status it needs to use the Created date 

 
4 REPLIES 4
123abc
Community Champion
Community Champion

To achieve your requirements of using the `USERELATIONSHIP` function with multiple criteria to switch dates based on the status column, you can create a DAX measure that sums up the loan amount while considering the relationship between the calendar table and the main table. Here's a step-by-step guide on how to do this:

1. Create a new DAX measure. In Power BI, you can do this by selecting "Modeling" from the top menu and then clicking "New Measure."

2. Use the `SUMX` function to iterate through the rows of your main table and calculate the sum of the loan amount based on your conditions. Here's a sample DAX formula:

```DAX
LoanAmountSum =
SUMX(
MainTable,
IF(
MainTable[Status] = "Approved",
CALCULATE(SUM(MainTable[Loan Amount]), USERELATIONSHIP(MainTable[Approved Date], Calendar[Date])),
CALCULATE(SUM(MainTable[Loan Amount]), USERELATIONSHIP(MainTable[Created Date], Calendar[Date]))
)
)
```

In this formula:

- `SUMX` iterates through each row of the MainTable.
- The `IF` statement checks the status column in each row. If the status is "Approved," it uses the `USERELATIONSHIP` function to establish the inactive relationship with the "Approved Date" and Calendar date. Otherwise, it uses the "Created Date" and Calendar date.
- `CALCULATE(SUM(MainTable[Loan Amount]), ...)` calculates the sum of the loan amount based on the appropriate relationship.

3. Once you've created the measure, you can add it to your visuals, and it will dynamically switch between the "Approved Date" and "Created Date" based on the status.

4. Create a date slicer using the Calendar table's date column. When you use this slicer, the `LoanAmountSum` measure will consider the appropriate date based on the status selected.

By following these steps, you can sum up the loan amount using the `USERELATIONSHIP` function with multiple criteria to switch dates based on the status column in Power BI.

DimaMD
Solution Sage
Solution Sage

@Madhu155154  hi , try it measure 

Amount_ApprovedDate = CALCULATE( SUM('table1'[Loan Amount]), USERELATIONSHIP(dates[Date],table1[Approved date]), 'table1'[Status:] = "Approved" )

DimaMD_0-1693811119437.png

 


__________________________________________

Thank you for your like and decision

__________________________________________

Greetings from Ukraine

To help me grow PayPal: embirddima@gmail.com

@DimaMD , Thank you answering for the question,

But I am getting Static Data, I want it to be dynamic, 

Can't we use userelation  function to switch the dates for specific Cretira 


Test File data userelation.pbix



ERD
Super User
Super User

@Madhu155154 , where are you going to use your measure? 

General approach is to use IF conditions along with CALCULATE and USERELATIONSHIP.

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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