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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Anonymous
Not applicable

Extract Date Quarter String and Year int columns IN POWERQUERY

Hi all,

 

I have 2 fct tables on quarter  level and I have to connect these 2 fct tables to my date table which is on day level. (the dim date is day level because I have more 3 fact tables on day level connected to it)

 

How do I extract the first day of the quarter from the columns?

 

The table has the columns Quarter and Year as String and Int, I already tried to convert to date format and when I do that the Year gets all messed up, the 2020 becomes like 1950.

 

QuarterYear
Q22020
Q42020
Q12019


and I need the below: (First day of the quarter)

 

QuarterYearDate Column
Q220201/04/2020
Q420201/09/2020
Q120191/01/2020

 


Thank you

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Inserted Text After Delimiter" = Table.AddColumn(Source, "Text After Delimiter", each Text.AfterDelimiter([Quarter], "Q"), type number),
    #"Changed Type1" = Table.TransformColumnTypes(#"Inserted Text After Delimiter",{{"Text After Delimiter", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each if [Text After Delimiter] = 1 then 1 else if [Text After Delimiter] = 2 then 4 else if [Text After Delimiter] = 3 then 7 else 10, type text),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Date", each "1/"&Number.ToText([Custom])&"/"&Number.ToText([Year])),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom1",{{"Date", type date}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Text After Delimiter", "Custom"})
in
    #"Removed Columns"

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Inserted Text After Delimiter" = Table.AddColumn(Source, "Text After Delimiter", each Text.AfterDelimiter([Quarter], "Q"), type number),
    #"Changed Type1" = Table.TransformColumnTypes(#"Inserted Text After Delimiter",{{"Text After Delimiter", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each if [Text After Delimiter] = 1 then 1 else if [Text After Delimiter] = 2 then 4 else if [Text After Delimiter] = 3 then 7 else 10, type text),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Date", each "1/"&Number.ToText([Custom])&"/"&Number.ToText([Year])),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom1",{{"Date", type date}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Text After Delimiter", "Custom"})
in
    #"Removed Columns"

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
selimovd
Super User
Super User

Hey @Anonymous ,

 

you can just check for the quarter and then return the corresponding month.
Try the following calculated column:

Date Column =
VAR vCalcMonth =
    SWITCH(
        'myTable'[Quarter],
        "Q1", 1,
        "Q2", 4,
        "Q3", 7,
        "Q4", 10
    )
RETURN
    DATE( 'myTable'[Year], vCalcMonth, 1 )

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

 

Helpful resources

Announcements
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.