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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Razan_Omoush
Frequent Visitor

How to refer to columns values of a table variable

Hi All,

I am trying to find the right formula in DAX for this and getting nowhere.
I want to create a measure based on date slicer selection,
the measure should calculate the claim amount for the claims that occurred on a date before the Max selected value of a Date slicer for only the claims in the period after the Max selected value of a Date slicer. In other words, I want my measure to do the following.

OS Amount=
VAR MAX_DATE_SLICER=CALCULATE (
MAX( 'Date'[Date] )
)
Var Ids_After_max_Date=ADDCOLUMNS ( CALCULATETABLE(
SUMMARIZE(CLAIM_TRANSACTION,CLAIM_TRANSACTION[CLAIM_ID]),
FILTER( CLAIM_TRANSACTION,CLAIM_TRANSACTION[TRANS_DATE] >= MAX_DATE_SLICER) ,
FILTER( CLAIM,CLAIM[CLAIM_STATUS]="Treatment Delivered" ) //// This is a related table 
),
"CLM_ID", CLAIM_TRANSACTION[CLAIM_ID]
)

Var Final_Amount= CALCULATE(SUM(CLAIM_TRANSACTION[TRANS_AMT_LC]),(CLAIM_TRANSACTION[TRANS_DATE] <= MAX_DATE_SLICER),CLAIM[CLAIM_ID] in VALUES(Ids_After_max_Date[CLM_ID] ))
return Final_Amount

my challenge is how to refer to the column values of a table variable. 
I tried to create a calculated table and then refer to its column in my measure using  VALUSES('calculated_table'[CLAIM_ID]) but, I ran into another challenge the selected slicer value did not work with the calculated table and the result was blank table.

this is the calculated table measure I created.
calculated_table =
Var MAX_DATE_SLICER=  CALCULATE (
                                    MAX( 'Date'[Date] )
                                               )
Var IDs_After_Max_Date= CALCULATETABLE(
                SUMMARIZE(CLAIM_TRANSACTION,CLAIM_TRANSACTION[CLAIM_ID]),
                FILTER( CLAIM_TRANSACTION,CLAIM_TRANSACTION[TRANS_DATE] >= MAX_DATE_SLICER)
                )
return IDs_After_Max_Date    

1 ACCEPTED SOLUTION
Daniel29195
Super User
Super User

@Razan_Omoush 

 

this is a modified version of your code 

OS Amount =
VAR MAX_DATE_SLICER =
    CALCULATE (
        MAX ( 'Date'[Date] )
    )
    
VAR Ids_After_max_Date =
selectcolumns(
    ADDCOLUMNS (
        CALCULATETABLE (
            SUMMARIZE (
                CLAIM_TRANSACTION,
                CLAIM_TRANSACTION[CLAIM_ID]
            ),
            FILTER (
                CLAIM_TRANSACTION,
                CLAIM_TRANSACTION[TRANS_DATE] >= MAX_DATE_SLICER
            ),
            FILTER (
                CLAIM,
                CLAIM[CLAIM_STATUS] = "Treatment Delivered"
            ) //// This is a related table 
        ),
        "CLM_ID", CLAIM_TRANSACTION[CLAIM_ID]
    ),
    "CLM_ID", [CLM_ID]
    )
    
VAR Final_Amount =
    CALCULATE (
        SUM ( CLAIM_TRANSACTION[TRANS_AMT_LC] ),
         CLAIM_TRANSACTION[TRANS_DATE] <= MAX_DATE_SLICER ,
        CLAIM[CLAIM_ID]
            IN  Ids_After_max_Date
    )
    
RETURN
    Final_Amount

 

let me know if it works for you . 

 

 

If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution !

It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠

View solution in original post

2 REPLIES 2
Daniel29195
Super User
Super User

@Razan_Omoush 

 

this is a modified version of your code 

OS Amount =
VAR MAX_DATE_SLICER =
    CALCULATE (
        MAX ( 'Date'[Date] )
    )
    
VAR Ids_After_max_Date =
selectcolumns(
    ADDCOLUMNS (
        CALCULATETABLE (
            SUMMARIZE (
                CLAIM_TRANSACTION,
                CLAIM_TRANSACTION[CLAIM_ID]
            ),
            FILTER (
                CLAIM_TRANSACTION,
                CLAIM_TRANSACTION[TRANS_DATE] >= MAX_DATE_SLICER
            ),
            FILTER (
                CLAIM,
                CLAIM[CLAIM_STATUS] = "Treatment Delivered"
            ) //// This is a related table 
        ),
        "CLM_ID", CLAIM_TRANSACTION[CLAIM_ID]
    ),
    "CLM_ID", [CLM_ID]
    )
    
VAR Final_Amount =
    CALCULATE (
        SUM ( CLAIM_TRANSACTION[TRANS_AMT_LC] ),
         CLAIM_TRANSACTION[TRANS_DATE] <= MAX_DATE_SLICER ,
        CLAIM[CLAIM_ID]
            IN  Ids_After_max_Date
    )
    
RETURN
    Final_Amount

 

let me know if it works for you . 

 

 

If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution !

It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠

Idrissshatila
Super User
Super User

@Daniel29195  check this out.



Did I answer your question? Mark my post as a solution! Appreciate your Kudos
Follow me on LinkedIn linkedIn
Vote for my Community Mobile App Idea

Proud to be a Super User!




Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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