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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
DemoFour
Responsive Resident
Responsive Resident

Create a Year Period column in M

Hi all, 

 

I have been learning M with the help of blogs to build a dimension table. I want to create a column for FY = 2020 - 2021

 

I can do this in Dax with 

Year Period = 
IF( 
    'Date'[Quarter Number] >= 4 , 
    'Date'[Year] - 1 & "-" & 'Date'[Year],
    'Date'[Year] & "-" & 'Date'[Year] +1
)

 

But if I do this in M then it does not like the & "-" & part

 

I guess this is an easy. . .  but I am new to M, but any help welcome on how to join the years with the + or - 1 please. 

 

Thanks 

1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

The equivalent M syntax would look like this (assuming your Date table is created with a query and is not a DAX table).  This also assumes your Year and Quarter columns are numbers (not text).  Note that M is case sensitive.

 

Year Period = 
if
    [Quarter Number] >= 4 then 
    Text.From([Year] - 1) & "-" & Text.From([Year]) else
    Text.From([Year]) & "-" & Text.From([Year] +1)

 

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
watkinnc
Super User
Super User

Try:

Year Period = VAR ly = TEXT(Date[Year]-1) VAR ny = TEXT(Date[Year]-1) VAR ty = TEXT(Date[Year] RETURN 

IF Date[Quarter Number] >= 4, ly&"-"&ty,

ty&"-"&ny 

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!
DemoFour
Responsive Resident
Responsive Resident

@watkinnc Thank you Nate, this did not work as written, but I will have an explore and see what I can do with your offered solution. 

 

Have a good day. 

mahoneypat
Employee
Employee

The equivalent M syntax would look like this (assuming your Date table is created with a query and is not a DAX table).  This also assumes your Year and Quarter columns are numbers (not text).  Note that M is case sensitive.

 

Year Period = 
if
    [Quarter Number] >= 4 then 
    Text.From([Year] - 1) & "-" & Text.From([Year]) else
    Text.From([Year]) & "-" & Text.From([Year] +1)

 

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


Morning @mahoneypat 

Thank you for the solution. 

 

Because I had made the Quarter Column with: 

 

= "Q" & [Quarter Number]

 


I just tried the same with the column names and & but I can see now that you need to use Text.From to tell the engine to take the value from the column and - 1

Thank you for posting up, have a good day Pat

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Top Solution Authors
Top Kudoed Authors