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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
ohnothimagain
Helper I
Helper I

How to CALCULATE VAR table with USERELATIONSHIP

Hello everyone,
I have a table below,and want to sum [Qty] on variable table by cumulative and using inactive relationship
between [Calculated] and Calendar table.

ohnothimagain_1-1723818834370.png

 

Ftd_sum2:=
VAR tbl = 
    SELECTCOLUMNS(
        FILTER(ALL('TEST_'), 'TEST_'[STS] = "〇"),
        "@Trg", 'TEST_'[PN]
      )
VAR Dis =DISTINCT(tbl)   
VAR Ftd = 
    CALCULATETABLE(                                    
            'TEST_',filter(allselected('TEST_'),'TEST_'[PN] IN Dis),                                             
               USERELATIONSHIP('Calendar'[Date],'TEST_'[Calculated])
                    )  
VAR Result =
    CALCULATE(
        SUM('TEST_'[Qty]),
        KEEPFILTERS(Ftd),filter(allselected('Calendar'),
                     'Calendar'[Date]<=max('Calendar'[Date]))
              )
return 
Result

 


Result is all blank..Upon checking the operarion,it caused when I added  USERELATIONSHIP on CACULATETABLE.

ohnothimagain_0-1723820320753.png


This might be related to following article,I have no idea to do what I needed by using LOOKUPVALUE.
USERELATIONSHIP in calculated column
Could anyone teach me how to correct it on Excel powerpivot??

Best regards,

4 REPLIES 4
sjoerdvn
Super User
Super User

I don't know what's going on with all those filters and table calculations, but if you want to calculate a cummulative sum on that inactive date column, try:

 

Ftd_sum2:=
VAR md = MAX('Calendar'[date])
RETURN CALCULATE(
	SUM('TEST_'[Qty]),
	USERELATIONSHIP('Calendar'[Date],'TEST_'[Calculated]),
	ALL('Calendar'),
	'Calendar'[Date]<=md)
)

 If you need additional filters, apply them to the page or visual filters... 

I'm sorry for my late reply.Yes,your suggestion can success at most of cases.
the key point is it uses relationship between "calculated column" and calender.

>This might be related to following article,but I have no idea to do what I needed by using >LOOKUPVALUE.
>USERELATIONSHIP in calculated column

jgeddes
Super User
Super User

The following measure might help you or at least get you pointed in the right direction.

Cumulative Sum = 
var _tbl = 
	DISTINCT(
		SELECTCOLUMNS(
		FILTER(ALL(TEST_), TEST_[STS] = "〇"),
		"@Trg", TEST_[PN]
	)
)
var _result = 
CALCULATE(
	SUM(TEST_[Qty]),
    ALL('calendar'),
	FILTER(TEST_, TEST_[Calculated] <= MAX(calendar[Date]) && TEST_[PN] in _tbl),
	USERELATIONSHIP(TEST_[Calculated], calendar[Date])
)
RETURN
_result

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Thank you for replying quickly! I tried right away,but result was unfortunately unsuccess.
-->putting userelationship on "calculated column" seems preventing

I've put this excel file on OneDrive,please teach me if you have more ideas.
OneDrive 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 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.