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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
MegaOctane1
Helper I
Helper I

Fix my measures to work with month name or date.

I have a dim Calendar and dim CalendarVisual

i have dimCalendar Year in slicer and dimCalendar MonthName in second slicer. 
I have a column chart where I will put a parameter in X axis. User can choose to see dates in x or month name in x axis. 

I have created two measures, and both work, but only if I either use dates or use Year and Month, not with month name.
If I use month name, it shows no data.

 

my measures:

Sales Calendar Date = 
VAR MaxDate = MAX('dim Calendar'[Calendar Date]) 
VAR MinDate = DATE(YEAR(MaxDate), 1, 1) 

VAR Result =  
    IF(
        HASONEVALUE('dim Calendar'[Year and month]) &&
            MAX( 'dim VisualCalendar'[Calendar Date] ) <= maxDate &&
            MIN( 'dim VisualCalendar'[Calendar Date] ) > MinDate,
        CALCULATE(
            [Net Amount],
            FILTER(ALL('dim Calendar'),
                'dim Calendar'[Calendar Date]= VALUES('dim VisualCalendar'[Calendar Date])
            )
        ),
        BLANK()
    )
RETURN
    Result

 

Sale Year and Month= 
VAR MaxDate = MAX('dim Calendar'[Calendar Date]) 
VAR MinDate = DATE(YEAR(MaxDate), 1, 1)

VAR Result =  
    IF(
        HASONEVALUE('dim Calendar'[Year and month]) &&
            MAX( 'dim VisualCalendar'[Calendar Date] ) <= maxDate &&
            MIN( 'dim VisualCalendar'[Calendar Date] ) > MinDate,
        CALCULATE(
            [Net Amount],
            FILTER(ALL('dim Calendar'),
                'dim Calendar'[Year and Month]= VALUES('dim VisualCalendar'[Year and Month])
            )
        ),
        BLANK()
    )
RETURN
    Result

 

1 ACCEPTED SOLUTION

Hi @MegaOctane1,

Thank you  for reaching out to the Microsoft fabric community forum.
Thank you @Jai-Rathinavel, for your response regarding the issue.

Year and Month are not unique by themselves since they repeat for each date in that month. That’s why we usually pair them with date-based filters like MAX/MIN to get accurate results.

You can combine both your measures into one using a SWITCH statement based on the user's selection (such as Date, Month Name, or YearMonth). However, the easiest and cleanest way to handle this is by using Field Parameters. This allows you to switch the X-axis dynamically in the visual without writing complex DAX.

Please find attached Pbix File and screenshot for your reference

vhjannapu_0-1748585513273.png

 

If I misunderstand your needs or you still have problems on it, please feel free to let us know.  
If the response has addressed your query, please Accept it as a solution and give a 'Kudos' so other members can easily find it

Best Regards,
Harshitha.
Community Support Team

View solution in original post

3 REPLIES 3
Jai-Rathinavel
Super User
Super User

@MegaOctane1 The problem occurs because "Month Name" by itself isn't unique—it repeats every year. To avoid confusion and ensure accurate filtering, you should include the Year along with the Month Name when applying filters. Please try out the below dax and see if it help.

 

Sale New =
VAR MaxDate = MAX('dim Calendar'[Calendar Date])
VAR MinDate = DATE(YEAR(MaxDate), 1, 1)

VAR Result =
    IF(
        (HASONEVALUE('dim Calendar'[Year and Month]) || HASONEVALUE('dim Calendar'[Month Name])) &&
        MAX('dim VisualCalendar'[Calendar Date]) <= MaxDate &&
        MIN('dim VisualCalendar'[Calendar Date]) > MinDate,
        CALCULATE(
            [Net Amount],
            FILTER(ALL('dim Calendar'),
                ('dim Calendar'[Year and Month] = VALUES('dim VisualCalendar'[Year and Month]) ||
                 ('dim Calendar'[Month Name] = VALUES('dim VisualCalendar'[Month Name]) &&
                  'dim Calendar'[Year] = VALUES('dim VisualCalendar'[Year])))
            )
        ),
        BLANK()
    )
RETURN
    Result

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Oh.. I will try. But Year and month is not unique either. This repeats as many times as there are dates?

 

can I combine both measures into one somehow?

Hi @MegaOctane1,

Thank you  for reaching out to the Microsoft fabric community forum.
Thank you @Jai-Rathinavel, for your response regarding the issue.

Year and Month are not unique by themselves since they repeat for each date in that month. That’s why we usually pair them with date-based filters like MAX/MIN to get accurate results.

You can combine both your measures into one using a SWITCH statement based on the user's selection (such as Date, Month Name, or YearMonth). However, the easiest and cleanest way to handle this is by using Field Parameters. This allows you to switch the X-axis dynamically in the visual without writing complex DAX.

Please find attached Pbix File and screenshot for your reference

vhjannapu_0-1748585513273.png

 

If I misunderstand your needs or you still have problems on it, please feel free to let us know.  
If the response has addressed your query, please Accept it as a solution and give a 'Kudos' so other members can easily find it

Best Regards,
Harshitha.
Community Support Team

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.