How does this formula Work in Power BI

bearcub

Well-known Member
Joined
May 18, 2005
Messages
701
Office Version
  1. 365
  2. 2013
  3. 2010
  4. 2007
Platform
  1. Windows
I have separate column for the Year, Quarter and Date. I have 3 records representing each quarter. I want to create a formula that will assignment the month associated with each quarter. The columns that i have in this table is this:

Code:
Year  Quarter Month
2012     1      1
2012     1      2
2012     1      3
2012     2      4
2012     2      5
2012     2      6
2012     3      7
2012     3      8
2012     3      9
2012     4      10
2012     4      11
2012     4      12

I added a custom column with the following formula which combined these 3 columns into this format.

1/1/2012
2/1/2012
3/1/2012
4/1/2012 ...

I used the #date function to perform this operation:

#date ([Year],([Quarter]-1)*3+[Month],1)

Question: What does the -1 *3 + [Month] do in the formula. The field headers in the formula are the column names.

I'm trying to wrap my head around how this works. Why the addition sign and Quarter -1 throws me.

What would be the equivalent formula in Excel?

Thank you for your help,

Michael
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
It’s just creating a date from year, quarter and month.

The year and the day of 1, are presumably self explanatory. The month calc just uses the month and quarter, so for May quarter is 2 and month within quarter is 2. (2 - 1)*3 + 2 is 5.

However, I don’t see how this works for your data as the months are not the month of the quarter 1 - 3, but the actual month.
 
Upvote 0
The confusing bit for me was January. I missed the fact that the Quarter and the month fields are included in the same formula (calculation)

For January, it would 1-1 =0 *3 = 0 + 1 = 1. My result would be 1/1/2012.

I forgot to add the [Month] field value to the result. I think the formula works because I have month number in the Month row.

If I were doing this in Excel itself, what would the formula look like (if I were wanted to join 3 columns into 1)?

Thank you for the explanation. I was definitely missing something here.

Michael
 
Upvote 0
The confusing bit for me was January. I missed the fact that the Quarter and the month fields are included in the same formula (calculation)

For January, it would 1-1 =0 *3 = 0 + 1 = 1. My result would be 1/1/2012.

I forgot to add the [Month] field value to the result. I think the formula works because I have month number in the Month row.

If I were doing this in Excel itself, what would the formula look like (if I were wanted to join 3 columns into 1)?

Thank you for the explanation. I was definitely missing something here.

Michael
 
Upvote 0

Forum statistics

Threads
1,214,396
Messages
6,119,268
Members
448,881
Latest member
Faxgirl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top