cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
stefans124
New Member

Month id to month name using power query

Hello there, im having a little challenge with my dash board. 

stefans124_0-1655800293668.png

stefans124_1-1655800332330.png

 

Here i have a slicer, that is connected to all other tables and makes them change information based on the month selected. So i have an issue with changing these 20221, 20222 etc. to their month names  (respectively, 20221 needs to be january, 20222 needs to be february etc.) I wanted to ask for help on how to do it, so that my slicer shows the names of the month not these numbers, and im skeptical that if i change it based on "how it think it should be done" then the relationships between tables might vanish.

I appreaciate your time for reading this and any help or solution will be appreciated 🙂

 

1 ACCEPTED SOLUTION
SpartaBI
Community Champion
Community Champion

Hi @stefans124,

Have a look at the following code

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMjJUitWBsIzgLGM4ywTOMoWzzOAsczjLAs6yhLMMDRBMhC2GQGtiAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [id_menesis = _t]),
    AddMonthName = Table.AddColumn(Source, "MonthName", each Date.ToText(Date.FromText([id_menesis],[Format="yyyyM"]),"MMMM"),type text),
    AddMonthNum = Table.AddColumn(AddMonthName, "MonthNum", each Int64.From(Text.Middle([id_menesis], 4,2)), Int64.Type)
in
    AddMonthNum

 

SpartaBI_1-1655893309489.png
You will need the MonthNum integer column to sort the month names. See this link



2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

View solution in original post

2 REPLIES 2
v-eqin-msft
Community Support
Community Support

Hi @stefans124 ,

 

You may firstly try @SpartaBI 'method using M in Power Query.

Mine is using DAX to create calculated columns:

Month Number = CONVERT( RIGHT([id_menesis], LEN([id_menesis])-4),INTEGER)
Month Name = FORMAT( DATE(LEFT([id_menesis],4),[Month Number],1),"mmmm")

Output:

Eyelyn9_0-1656382410240.png

Eyelyn9_1-1656382516176.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

SpartaBI
Community Champion
Community Champion

Hi @stefans124,

Have a look at the following code

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMjJUitWBsIzgLGM4ywTOMoWzzOAsczjLAs6yhLMMDRBMhC2GQGtiAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [id_menesis = _t]),
    AddMonthName = Table.AddColumn(Source, "MonthName", each Date.ToText(Date.FromText([id_menesis],[Format="yyyyM"]),"MMMM"),type text),
    AddMonthNum = Table.AddColumn(AddMonthName, "MonthNum", each Int64.From(Text.Middle([id_menesis], 4,2)), Int64.Type)
in
    AddMonthNum

 

SpartaBI_1-1655893309489.png
You will need the MonthNum integer column to sort the month names. See this link



2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors