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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
likhithar
Helper III
Helper III

Totals Issue with USERELATIONSHIP DAX Function

Hello All,

I have the Fact Table Data in the below format.

likhithar_0-1681280218611.png

I created a Date Table 
Date Table = calendar(DATE(2020,04,01),DATE(2023,12,31))

And Relationship is like 
Active Relationship between Fact[Mat Date] - Date Table[Date]
InActive Relationship betweenFact[Avail Date]- Date Table[Date]

My scenario is 

likhithar_1-1681280726318.png

I have Start Date (01-04-2022) and End Date(30-09-2022) as date Filter from Date Table and 
I will be getting 4 rows with my selection,to get Yellow Higlighted row(5 th row)

I created a measure using the DAX 
Availed Date =
var a = CALCULATE(MAX(Fact[Avail Date]),USERELATIONSHIP(Fact[Avail Date],Date Table[Date]))
var b = MAX(Fact[Avail Date])
return
IF(ISBLANK(a),b,a)
I'm getting correct result with the above DAX.

The same logic for Amt 
Amt =
var a = CALCULATE(SUM(Fact[Amt]),USERELATIONSHIP(Fact[Avail Date],Date Table[Date]))
var b = SUM(Fact[Amt])
return
IF(ISBLANK(a),b,a)
I should get the Total 40833.6 but I'm getting 29,166.69 (Total- It's excluding the first row i.e, 01-03-2022).

Here's the Link for the pbis File

https://drive.google.com/file/d/14s8Nlak4dU4WW3nKY69VJL03duVRU69E/view?usp=sharing

Can anyone suggest the alternative for this!!!
TIA

1 ACCEPTED SOLUTION
likhithar
Helper III
Helper III

Hello All,
I got the solution for the issue which I posted above.

1.First I figured out the Mat Date which is greater than End Date(or Max Date in our Slicer Selection)based on Avail Date using USERELATIONSHIP DAX Function and created a Flag for it.

Flag =
var a = MAX('Date Table'[Date])
var b = CALCULATE(MAX(Sheet2[Mat Date]),USERELATIONSHIP('Date Table'[Date],Sheet2[Avail Date]))
return
IF(b>a,1,0)
2.Derived Amt for the Flag output if it's 1.
Amt_Last Row =
var a = MAX('Date Table'[Date])
var d = CALCULATE(SUM(Sheet2[Amt]),USERELATIONSHIP('Date Table'[Date],Sheet2[Avail Date]),Sheet2[Mat Date]>=a)
return
IF([Flag]=1,d)
3.Then Added the Amt from Fact Table with Step 2 Result.
Amt_Result =
var a = [Amt_Last Row]
var b = SUM(Sheet2[Amt])
return
a+b
Here's my Output
likhithar_0-1681836456829.png

 

Thanks everyone  for the replies.
Here's the Link to access the pbix File
 

 

View solution in original post

4 REPLIES 4
likhithar
Helper III
Helper III

Hello All,
I got the solution for the issue which I posted above.

1.First I figured out the Mat Date which is greater than End Date(or Max Date in our Slicer Selection)based on Avail Date using USERELATIONSHIP DAX Function and created a Flag for it.

Flag =
var a = MAX('Date Table'[Date])
var b = CALCULATE(MAX(Sheet2[Mat Date]),USERELATIONSHIP('Date Table'[Date],Sheet2[Avail Date]))
return
IF(b>a,1,0)
2.Derived Amt for the Flag output if it's 1.
Amt_Last Row =
var a = MAX('Date Table'[Date])
var d = CALCULATE(SUM(Sheet2[Amt]),USERELATIONSHIP('Date Table'[Date],Sheet2[Avail Date]),Sheet2[Mat Date]>=a)
return
IF([Flag]=1,d)
3.Then Added the Amt from Fact Table with Step 2 Result.
Amt_Result =
var a = [Amt_Last Row]
var b = SUM(Sheet2[Amt])
return
a+b
Here's my Output
likhithar_0-1681836456829.png

 

Thanks everyone  for the replies.
Here's the Link to access the pbix File
 

 

grantsamborn
Solution Sage
Solution Sage

Hi @likhithar 

I hope I understood this correctly but I'm not sure it has to with [Availed Date].

 

If your date table is filtered by 2022-04-01 to 2022-09-30, the last row wouldn't be included in the total since the Mat Date is 2022-12-26 --- outside of your filter range.

 

pbix: likhithar - 1.pbix  (I replaced your date table.)

 

Let me know if that makes sense.

Grant

 

@grantsamborn  the last row should include in the reporting because Avail Date(01-09-2022) is before Max Date from Date Table(30-09-2022)

Anonymous
Not applicable

Hi @likhithar ,

 

Do all the fields of your visual come from the fact table? According to your description, when the slicer is filtered, only data that meets the slicer criteria is displayed. As follows:

vtangjiemsft_2-1681455024653.png

If you want to show all totals, you can create a measure to display as a card visual.

 

Total = CALCULATE(SUM('Fact'[Amt]),FILTER(ALL('Fact'),'Fact'[ID]=MAX('Fact'[ID])))

vtangjiemsft_1-1681454978198.png

Or you can delete the slicer and set conditional formatting to highlight the data you don't want to display, so that the total is also correct.

vtangjiemsft_3-1681455540650.png

 

 

Best Regards,

Neeko Tang

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

 

 

 

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Kudoed Authors