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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Thomas94401
Helper I
Helper I

Convert Month to string like M1 depending on the filter

Hi, 

 

I have a Sales table by month: 

DateOptionSales
Jan-2019A1
Jan-2019B2
Feb-2019A3
Feb-2019B4
Mars-2019A5
Mars-2019B6

 

I want to build a groupby table summing sales. For example, an output I would like : 

If I filter on Date between Feb2019 and June2019 : I would like : 

DateSum  of sales
M17
M211

 

with :

- M1 = first month of the filter

- M2 = second month of the filter ...

 

Do you know if it is possible to build this column ? 

 

Thanks in advance, 

 

I tried everything and cannot obtain this result 😞

        

1 ACCEPTED SOLUTION

I did it on an existing model, so you can adapt same approach.  I made the disconnected table called MonthTable.

 

mahoneypat_0-1635115564851.png

 

And my Date table already had a column for the MonthEnding, so I used that in this measure to get the result shown.

 

SlicerMonth =
VAR slicermon =
    MIN ( MonthTable[MonthsAway] )
VAR EOMminslicerdate =
    EOMONTH ( MIN ( 'Date'[Date] )slicermon )
RETURN
    CALCULATE ( [Total Sales], 'Date'[MonthEnding] = EOMminslicerdate )

 

 

mahoneypat_1-1635115608114.png

 

Pat

 

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

4 REPLIES 4
Thomas94401
Helper I
Helper I

Hi, Thanks a lot for your help ! 

 

I created this PBIX and the disconnected table. I was stuck on how you create the variable MonthFromSelection ?

 

Thomas94401_0-1635084570452.png

 

Thomas94401_1-1635084670340.png

 

mahoneypat
Microsoft Employee
Microsoft Employee

To do that, you need to create a disconnected table like the one below, and then in a variable in your measure calculate the month that would be that many MonthsFromSelection from the min date from the slicer.  You would then return your measure (sum in your case) for that month.

 

Month

MonthsFromSelection

M1 0
M2 1
M3 2

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


 

Hi, Thanks a lot for your help ! 

 

I created this PBIX and the disconnected table. I was stuck on how you create the variable MonthFromSelection ?

Thomas94401_0-1635092749749.png




Thomas94401_1-1635092763608.png

 

 

I did it on an existing model, so you can adapt same approach.  I made the disconnected table called MonthTable.

 

mahoneypat_0-1635115564851.png

 

And my Date table already had a column for the MonthEnding, so I used that in this measure to get the result shown.

 

SlicerMonth =
VAR slicermon =
    MIN ( MonthTable[MonthsAway] )
VAR EOMminslicerdate =
    EOMONTH ( MIN ( 'Date'[Date] )slicermon )
RETURN
    CALCULATE ( [Total Sales], 'Date'[MonthEnding] = EOMminslicerdate )

 

 

mahoneypat_1-1635115608114.png

 

Pat

 

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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.

Top Solution Authors