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
fab_rez_mil
Frequent Visitor

Create Conditional Column with Two Dynamic Filter Parameter

I have a table ‘RmR (unik)’ with the primary key information [ins_no], which corresponds to the installation number of a product. In this table, I also have the column with the name of the sales expert who is responsible for the installation in the column [Name], and the corresponding commercial year/month in which the installation was executed, information given in the column [comm-MonthTM]. The format of the column [comm-MonthTM] is text, with its values being the corresponding concatenation of the year and month number, e.g., 202202 (Year = 2022, month = 02). It is possible to see the table below for better understanding.

 

fab_rez_mil_2-1646390908608.png

 

I want to create a conditional column in this table ‘RmR (unik)’, which gives me for each row the “count of installations a salesperson did in the corresponding commercial year/month”.  Note that the names in the column name repeats, as it is not a unique value, since sales expert can do more than one installation. I want to this calculation to be dynamic, that is, the row will do the calculation with its corresponding commercial year/month column [comm-MonthTM]  and sales expert column [Name].

I have tried to do the following created column, doing a filter using two different related tables ‘Dim_Names’ which is the table with all the sales expert names (Primary Key ) and ‘Date (2)’, which is a table with the corresponding days and commercial year/month.  

 

 

Total Inst = calculate(

    COUNT('RmR (unik)'[ins_no]),

    filter(Dim_Names, Dim_Names[Name] = 'RmR (unik)'[Name]),

    filter('RmR (unik)', 'RmR (unik)'[comm-MonthTM] = RELATED('Date (2)'[Commercial month]))

)

 

 

However, the result in the created column [Total Inst] corresponds to the total count of installations a sales expert did in the whole data source, that is, it is not filtering by the corresponding commercial year/month column, as you can see below. The 

 

fab_rez_mil_3-1646390946967.png

In the image below I changed in the DAX formula the commercial year/month for a specific text instead, defined as “202202”. In this case it filters correctly for the month of Feb 2022, only. But I want to be correct for the other commercial year/month too.

 

 

Total Inst = calculate(
    COUNT('RmR (unik)'[ins_no]),
    filter(Dim_Names,Dim_Names[Name] = 'RmR (unik)'[Name]),
    filter('RmR (unik)', 'RmR (unik)'[comm-MonthTM] = "202202")
)

 

 

For example, for the sales expert “highlighted in red” the calculated amount is correct for the commercial year/month 0f "202202" (feb), but not for "202203" (mar).

 

fab_rez_mil_4-1646391164599.png

 

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

If it needs to be a calculated column then the below should work I think

Total inst =
var currentSalesPerson = 'RmR (unik)'[Name]
var currentMonth = 'RmR (unik)'[comm-MonthTM]
var result = CALCULATE( COUNTROWS( 'RmR (unik)')
REMOVEFILTERS('RmR (unik)'),
TREATAS( { ( currentSalesPerson, currentMonth ) }, 'RmR (unik)'[Name], 'RmR (unik)'[comm-MonthTM])
)
return result

It might be better as a measure, in which case the first 2 variables would need to use SELECTEDVALUE on the appropriate columns

View solution in original post

2 REPLIES 2
fab_rez_mil
Frequent Visitor

It worked just perfectly. Thanks a lot!

johnt75
Super User
Super User

If it needs to be a calculated column then the below should work I think

Total inst =
var currentSalesPerson = 'RmR (unik)'[Name]
var currentMonth = 'RmR (unik)'[comm-MonthTM]
var result = CALCULATE( COUNTROWS( 'RmR (unik)')
REMOVEFILTERS('RmR (unik)'),
TREATAS( { ( currentSalesPerson, currentMonth ) }, 'RmR (unik)'[Name], 'RmR (unik)'[comm-MonthTM])
)
return result

It might be better as a measure, in which case the first 2 variables would need to use SELECTEDVALUE on the appropriate columns

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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