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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
kent-culpepper
Frequent Visitor

DAX Expression - Return Max Date x Groups

I am running into a problem with an aggregation re: a closing\ ending balance for the max months by quarter.

 

I have illustrated the issue below and provided my current DAX expression (which is working fine when the user is selecting to view by Month but overstating the balance\value when selecting to view quarters).

 

kentculpepper_0-1697657391812.png

 

AV_Last_N_Period = 
VAR Selected_Period = SELECTEDVALUE(Calendar_Period[Period_XRef])
VAR Selected_Horizon = SELECTEDVALUE(Calendar_Horizon[No_Periods])
VAR Selected_Month_Date = MAX('Calendar'[Month_Date])
VAR Month_Date_Horizon = DATESINPERIOD(Calendar_Filter_Month[Month_Date],Selected_Month_Date,Selected_Horizon,MONTH)
VAR Quarter_Date_Horizon = DATESINPERIOD(Calendar_Filter_Quarter[Month_Date],Selected_Month_Date,Selected_Horizon,QUARTER)
VAR Result =
    IF(Selected_Period = "Months",
    CALCULATE(
        SUM(AUM[Asset_Value]),
        REMOVEFILTERS('Calendar'),
        KEEPFILTERS(Month_Date_Horizon),
        USERELATIONSHIP('Calendar'[Month_Date],Calendar_Filter_Month[Month_Date])
    ),
     CALCULATE(
        SUM(AUM[Asset_Value]),
        REMOVEFILTERS('Calendar'),
        KEEPFILTERS(Quarter_Date_Horizon),
        USERELATIONSHIP('Calendar'[Month_Date],Calendar_Filter_Quarter[Month_Date])
    ))   
RETURN
    Result
1 ACCEPTED SOLUTION
kent-culpepper
Frequent Visitor

Thanks for response.

 

I added a column on my facts table for CLOSINGBALANCEQUARTER and this seems to solve it.

View solution in original post

4 REPLIES 4
kent-culpepper
Frequent Visitor

Thanks for response.

 

I added a column on my facts table for CLOSINGBALANCEQUARTER and this seems to solve it.

Abhinav054
Helper I
Helper I

Ok. In this i have added BLANK() filter, so it ensures tables are empty when the user selects to view by a different period

AV_Last_N_Period =
VAR Selected_Period = SELECTEDVALUE(Calendar_Period[Period_XRef])
VAR Selected_Horizon = SELECTEDVALUE(Calendar_Horizon[No_Periods])
VAR Selected_Month_Date = MAX('Calendar'[Month_Date])

VAR Month_Date_Horizon =
IF(
Selected_Period = "Months",
DATESBETWEEN(
Calendar_Filter_Month[Month_Date],
Selected_Month_Date,
EDATE(Selected_Month_Date, -Selected_Horizon + 1),
MONTH
),
BLANK()
)

VAR Quarter_Date_Horizon =
IF(
Selected_Period = "Quarters",
DATESBETWEEN(
Calendar_Filter_Quarter[Month_Date],
Selected_Month_Date,
EDATE(Selected_Month_Date, -Selected_Horizon + 1),
QUARTER
),
BLANK()
)

VAR Result =
IF(
Selected_Period = "Months",
CALCULATE(
SUM(AUM[Asset_Value]),
REMOVEFILTERS('Calendar'),
KEEPFILTERS(Month_Date_Horizon),
USERELATIONSHIP('Calendar'[Month_Date], Calendar_Filter_Month[Month_Date])
),
CALCULATE(
SUM(AUM[Asset_Value]),
REMOVEFILTERS('Calendar'),
KEEPFILTERS(Quarter_Date_Horizon),
USERELATIONSHIP('Calendar'[Month_Date], Calendar_Filter_Quarter[Month_Date])
)
)

RETURN
Result



kent-culpepper
Frequent Visitor

No that doesnt work.

Abhinav054
Helper I
Helper I

hii, try this code

AV_Last_N_Period =
VAR Selected_Period = SELECTEDVALUE(Calendar_Period[Period_XRef])
VAR Selected_Horizon = SELECTEDVALUE(Calendar_Horizon[No_Periods])
VAR Selected_Month_Date = MAX('Calendar'[Month_Date])
VAR Month_Date_Horizon = DATESBETWEEN(
Calendar_Filter_Month[Month_Date],
Selected_Month_Date,
EDATE(Selected_Month_Date, -Selected_Horizon + 1),
MONTH
)
VAR Quarter_Date_Horizon = DATESBETWEEN(
Calendar_Filter_Quarter[Month_Date],
Selected_Month_Date,
EDATE(Selected_Month_Date, -Selected_Horizon + 1),
QUARTER
)
VAR Result =
IF(
Selected_Period = "Months",
CALCULATE(
SUM(AUM[Asset_Value]),
REMOVEFILTERS('Calendar'),
KEEPFILTERS(Month_Date_Horizon),
USERELATIONSHIP('Calendar'[Month_Date], Calendar_Filter_Month[Month_Date])
),
CALCULATE(
SUM(AUM[Asset_Value]),
REMOVEFILTERS('Calendar'),
KEEPFILTERS(Quarter_Date_Horizon),
USERELATIONSHIP('Calendar'[Month_Date], Calendar_Filter_Quarter[Month_Date])
)
)
RETURN
Result

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.