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

View all the Fabric Data Days sessions on demand. View schedule

Reply
Harper146
Regular Visitor

Dax Formula Help - Filters

Hi,

I'm new to Power BI and the DAX language. I'm struggling to filter my calculated measure by a dimension.

The below Dax formula calculates the previous months new customers in a custom financial calendar:

 

 PrevMonNActives =
Var CurrentMonth = SELECTEDVALUE(Query[Fiscal Period])
Var CurrentYear = SELECTEDVALUE(Query[Fiscal Year])
Var Maxmonth = calculate( Max (Query[Fiscal Period]), all (Query))

Return
if (HASONEVALUE(Query[Fiscal Period]),
sumx (
FILTER(all (Query),
if(CurrentMonth = 1,
Query[Fiscal Period] = Maxmonth && 'Query'[Fiscal Year] = CurrentYear - 1,
Query[Fiscal Period] = CurrentMonth -1 && Query[Fiscal Year] = CurrentYear)),
Query[NewActives]),
Blank())

 

The formula works when only one product data is entered but when I entered the rest of the products the filter slicer does not apply.

 

Alternativly I created a date column "Date = DATE(Query[Fiscal Year],Query[Fiscal Period],1)"  which makes it much simpler to calculate the previous month and solves the filter issue but the date hierachy only shows month name and it needs to be month number. = Month(query[date]) failed to work as well.

 

A solution to either problem would be much appreciated!

 

Thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Harper146,

 

You can try to use below measure to calculate difference:

Measure =
VAR fiscYear =
    SELECTEDVALUE ( Table1[Fiscal Year ] )
VAR fiscPeriod =
    SELECTEDVALUE ( Table1[Fiscal Period] )
VAR currProduct =
    SELECTEDVALUE ( Table1[Product] )
RETURN
    CALCULATE (
        SUM ( Table1[New Customers] ),
        VALUES ( Table1[Fiscal Year] ),
        VALUES ( Table1[Fiscal Period] ),
        VALUES ( Table1[Product] )
    )
        - CALCULATE (
            SUM ( Table1[New Customers] ),
            FILTER (
                ALL ( Table1 ),
                Table1[Product] IN VALUES ( Table1[Product] )
                    && Table1[Fiscal Year]
                        = IF ( fiscPeriod = 1, fiscYear - 1, fiscYear )
                    && Table1[Fiscal Period]
                        = IF ( fiscPeriod = 1, 12, fiscPeriod - 1 )
            )
        )

28.PNG

 

Regards,

Xiaoxin Sheng

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @Harper146,

 

SELECTEDVALUE and HASONEVALUE function only works for single row content, it will return blank if current contents contains or summarize multiple records.  So you're formula not works for multiple selection.

 

BTW, you can use allselected function to get multiple selection values, but it obviously can't use on your original condition. Please provide sample sample data and expected result to help us clarify your requirement.

 

Regards,

Xiaoxin Sheng

Hi Xiaoxin,

 

Ah that makes sense, thanks. please see some sample data below:

 

Fiscal Year Fiscal PeriodProductNew CustomersNew TurnoverRetained customersRetained Turnover
20171Product A                         500                10,000                              3,000                         30,000
20171Product B                         200                  5,000                              2,000                         25,000
20172Product A                         400                  9,000                              3,100                         32,000

 

I'm trying to add a colum with the previous periods transactions to the table which will alow me to calculate the Month on Month change.

 

Thanks

Sam

Anonymous
Not applicable

Hi @Harper146,

 

You can try to use below measure to calculate difference:

Measure =
VAR fiscYear =
    SELECTEDVALUE ( Table1[Fiscal Year ] )
VAR fiscPeriod =
    SELECTEDVALUE ( Table1[Fiscal Period] )
VAR currProduct =
    SELECTEDVALUE ( Table1[Product] )
RETURN
    CALCULATE (
        SUM ( Table1[New Customers] ),
        VALUES ( Table1[Fiscal Year] ),
        VALUES ( Table1[Fiscal Period] ),
        VALUES ( Table1[Product] )
    )
        - CALCULATE (
            SUM ( Table1[New Customers] ),
            FILTER (
                ALL ( Table1 ),
                Table1[Product] IN VALUES ( Table1[Product] )
                    && Table1[Fiscal Year]
                        = IF ( fiscPeriod = 1, fiscYear - 1, fiscYear )
                    && Table1[Fiscal Period]
                        = IF ( fiscPeriod = 1, 12, fiscPeriod - 1 )
            )
        )

28.PNG

 

Regards,

Xiaoxin Sheng

Thanks Xiaoxin, works perfectly 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors