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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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