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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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
ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.