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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
SamOvermars
Helper I
Helper I

Dax measure to calculate current year if no filter is selected

Hello, 

I have a slicer that has the following column 

MY = FORMAT(DimDate[FullDate], "mmm-yy")
It will filter the dashboard based on the month and year.
I need to create a card that will show the Current month to budget and the month will be changed based on the above slicer.
For example if I pick July-21 it will compare the july21 data to Julys budget.
so far I created this measure for the card

Var CurrentMonth = CALCULATE(SUM(Table[Price]), FILTER(DimDate, MONTH(DimDate[FullDate]) = MONTH(TODAY()) && YEAR(DimDate[FullDate] = YEAR(TODAY() ))))
Var Budget = calculate(SUM(Budget[MonthlyBudget]))

Return CurrentMonth/Budget

 

but for somereason then my slicer will work only if something is selected. I want the card to show current year and month data if nothing is selected in the slicer and will dynamically change if something is selected in the slicer. How can I do that ?

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @SamOvermars ,

According to your description, in your formula, the below code only related to the current year and month but not the value selected in the slicer. Also, the Budget table will also filtered by the slicer, if you want to show current year and month data if nothing is selected in the slicer, you should also add filter in the variable Budget.

FILTER(DimDate, MONTH(DimDate[FullDate]) = MONTH(TODAY()) && YEAR(DimDate[FullDate] = YEAR(TODAY() ))

I create a sample.

Table:

vkalyjmsft_0-1658828207913.png

DimDate table:

vkalyjmsft_1-1658828242007.png

Budget table:

vkalyjmsft_2-1658828357085.png

Here's my solution, create a measure.

Measure =
VAR _T1 =
    FILTER (
        DimDate,
        MONTH ( DimDate[FullDate] ) = MONTH ( MAX ( 'DimDate'[FullDate] ) )
            && YEAR ( DimDate[FullDate] = YEAR ( MAX ( 'DimDate'[FullDate] ) ) )
    )
VAR _T2 =
    FILTER (
        DimDate,
        MONTH ( DimDate[FullDate] ) = MONTH ( TODAY () )
            && YEAR ( DimDate[FullDate] = YEAR ( TODAY () ) )
    )
VAR _CurrentMonth =
    IF (
        ISFILTERED ( DimDate[MY] ),
        CALCULATE ( SUM ( 'Table'[Price] ), _T1 ),
        CALCULATE ( SUM ( 'Table'[Price] ), _T2 )
    )
VAR _Budget =
    IF (
        ISFILTERED ( DimDate[MY] ),
        CALCULATE ( SUM ( 'Budget'[MonthlyBudget] ), _T1 ),
        CALCULATE ( SUM ( 'Budget'[MonthlyBudget] ), _T2 )
    )
RETURN
    _CurrentMonth / _Budget

Get the correct result.

vkalyjmsft_3-1658828439454.png

vkalyjmsft_4-1658828469365.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

View solution in original post

2 REPLIES 2
v-yanjiang-msft
Community Support
Community Support

Hi @SamOvermars ,

According to your description, in your formula, the below code only related to the current year and month but not the value selected in the slicer. Also, the Budget table will also filtered by the slicer, if you want to show current year and month data if nothing is selected in the slicer, you should also add filter in the variable Budget.

FILTER(DimDate, MONTH(DimDate[FullDate]) = MONTH(TODAY()) && YEAR(DimDate[FullDate] = YEAR(TODAY() ))

I create a sample.

Table:

vkalyjmsft_0-1658828207913.png

DimDate table:

vkalyjmsft_1-1658828242007.png

Budget table:

vkalyjmsft_2-1658828357085.png

Here's my solution, create a measure.

Measure =
VAR _T1 =
    FILTER (
        DimDate,
        MONTH ( DimDate[FullDate] ) = MONTH ( MAX ( 'DimDate'[FullDate] ) )
            && YEAR ( DimDate[FullDate] = YEAR ( MAX ( 'DimDate'[FullDate] ) ) )
    )
VAR _T2 =
    FILTER (
        DimDate,
        MONTH ( DimDate[FullDate] ) = MONTH ( TODAY () )
            && YEAR ( DimDate[FullDate] = YEAR ( TODAY () ) )
    )
VAR _CurrentMonth =
    IF (
        ISFILTERED ( DimDate[MY] ),
        CALCULATE ( SUM ( 'Table'[Price] ), _T1 ),
        CALCULATE ( SUM ( 'Table'[Price] ), _T2 )
    )
VAR _Budget =
    IF (
        ISFILTERED ( DimDate[MY] ),
        CALCULATE ( SUM ( 'Budget'[MonthlyBudget] ), _T1 ),
        CALCULATE ( SUM ( 'Budget'[MonthlyBudget] ), _T2 )
    )
RETURN
    _CurrentMonth / _Budget

Get the correct result.

vkalyjmsft_3-1658828439454.png

vkalyjmsft_4-1658828469365.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

Migasuke
Memorable Member
Memorable Member

Hi @SamOvermars ,

To apply the logic when something is filtered is good to  use ISFILTERED and IF. So basically you should have your measure for latest period and for selection. Then you only need to use those two measures and combine it with functions above.

Some sample measure looks like this:

MyMeasure =
var _SelectedRevenue = SUM('Table'[REVENUE])
var _LatestMonth = CALCULATE(_SelectedRevenue,LASTDATE('Table'[DateColum]))

Return

IF(
ISFILTERED('DimColumn'[MMM-YYYY]),
                 _SelectedRevenue,
                _LatestMonth
)



If my answer was helpful please give me a Kudos or even accept as a Solution.

Let's connect on LinkedIn!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 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.