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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
winniexlee
New Member

Filter card when selected and show default value when not selected

Hi Experts,

 

I have this data here whereas my table has these 3 columns:

1. Month

2. Year

3. Employee Name

 

I want my Card to show the distinctcount of employee name on the latest Month & Year by default, and show the selected Month and Year if there is any selection. 

 

Kindly advise! Thank you!

6 REPLIES 6
FreemanZ
Super User
Super User

hi   @winniexlee 

try like:

Measure = 
VAR _MaxYear = CALCULATE(MAX(TableName[Year]), ALL(TableName[Year]))
VAR _MaxMonth =
MAXX(
    FILTER(TableName, TableName[Year] = _MaxYear), 
    TableName[Month]
)
VAR _CountMax = 
CALCULATE(
    DISTINCTCOUNT(TableName[Employee Name]),
    TableName[Year] = _MaxYear,
    TableName[Month] =_MaxMonth
 )
RETURN
IF(
    NOT ISFILTERED(TableName[Year]) || ISFILTERED(TableName[Month]),
    _CountMax,
    DISTINCTCOUNT(TableName[Employee Name])
)

hi @winniexlee 

tried with such dataset:

FreemanZ_0-1673233680501.png

 

it worked liked this:

FreemanZ_1-1673233706291.pngFreemanZ_2-1673233726614.pngFreemanZ_3-1673233751931.png

 

Hihi, the result is not showing correctly.

 

I forgotten to mention that i have a column name "Employment Type" in another table, whereas i only want to look at those that are labour supply or permanent employees. Is it possible to use Month Name instead of Month Number also?

hi @winniexlee 

1. you can place a slicer or filter for labour supply or permanent types.

2. Month Name instead of Month Number? seems fine. Just give it a try. 

 

p.s. please consider @someone, if you seek further suggestions. 

@FreemanZ apologies, I already have a Slicer for Month, Year and Employment Type.

 

HeadcountByDate =
VAR _MaxYear = CALCULATE(MAX(TableName[Year]), ALL(TableName[Year]))
VAR _MaxMonth =
MAXX(
    FILTER(TableName [Year] = _MaxYear),
    TableName [Month Name]
)
VAR _CountMax =
CALCULATE(
    DISTINCTCOUNT(TableName [NAME]),
    TableName [Year] = _MaxYear,
    TableName [Month Name] =_MaxMonth,
    OR(TableName [Emp Type] = "Labour Supply",TableName [Emp Type] = "Perm" ))
RETURN
IF(
    NOT ISFILTERED(TableName [Year]) || NOT ISFILTERED(TableName [Month Name]),
    _CountMax,
    CALCULATE(
    DISTINCTCOUNT(TableName [NAME]),TableName [Emp Type] = "Labour Supply" || TableName [Emp Type] = "Perm" ))
 
The above is working for the default value. But whenever i selected either a Year/Month/Employment Type, the number is a little bit off.

hi @winniexlee  

try like:

HeadcountByDate =
VAR _MaxYear = CALCULATE(MAX(TableName[Year]), ALL(TableName[Year]))
VAR _MaxMonth =
MAXX(
    FILTER(TableName [Year] = _MaxYear),
    TableName [Month Name]
)
VAR _CountMax =
CALCULATE(
    DISTINCTCOUNT(TableName [NAME]),
    TableName [Year] = _MaxYear,
    TableName [Month Name] =_MaxMonth,
     ALL(TableName [Emp Type])
RETURN
IF(
    NOT ( ISFILTERED(TableName[Year]) || ISFILTERED(TableName[Month Name]) || ISFILTERED(TableName[Emp Type] )
    _CountMax,
    DISTINCTCOUNT(TableName [NAME])
)

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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