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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It 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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors