cancel
Showing results for
Did you mean:

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Anonymous
Not applicable

## Power Query Nested IF AND Statement

Hi All,

I am working with the fiscal calendar below:

January: 01/01/2018 - 01/26/2016

February: 01/27/2018 - 02/23/2018

I would like to create a new column in Power Query that identifies the fiscal month a customer wants his/her order. If Customer1 wants his product on January 5, 2018 and Customer2 wants her product on January 29, 2018 I would like the fiscal month to be returned in a new column. Fiscal Month.

So I would like the below to happen where columns "Customer" and "Requested Date" are given I want this query to return the column "Fiscal Date:"

Customer | Requested Date | Fiscal Date

Customer1 | 01/05/2018 | 01/01/2018

Customer2 | 01/29/2018 | 02/01/2018

I am aware that something similar to Excel and DAX's IF AND statement would need to be used, but I am not very familiar with PowerQuery.

1 ACCEPTED SOLUTION
Employee

Hi @Anonymous,

Please refer to the snapshot below and try the formula. Your sample is too short. So I just hardcode these rules.

`if [Requested Date] >= #date(2018, 1, 1) and [Requested Date] <= #date(2018, 1, 26) then #date(2018, 1, 1) else if [Requested Date] >= #date(2018, 1, 27) and [Requested Date] <= #date(2018, 2, 23) then #date(2018, 2, 1) else #date(9999, 12, 31)`

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
5 REPLIES 5
Employee

Hi @Anonymous,

Please refer to the snapshot below and try the formula. Your sample is too short. So I just hardcode these rules.

`if [Requested Date] >= #date(2018, 1, 1) and [Requested Date] <= #date(2018, 1, 26) then #date(2018, 1, 1) else if [Requested Date] >= #date(2018, 1, 27) and [Requested Date] <= #date(2018, 2, 23) then #date(2018, 2, 1) else #date(9999, 12, 31)`

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

IF Primary Discipline is blank Get value from Discipline & even if Discipline is blank Get value from Attribute 4 Column and Add new Column “WIR Discipline”

Anonymous
Not applicable

This works for what I need it for!

Turns out there is a difference between a date column and a dattime column so I had to adjust your solution slightly to reflect this. I can see how updating this once a new fiscal calendar comes out may be a pain though.

Solution Specialist

Do you have a calendar table in your model that represents your fiscal calendar?  As long as that calendar table has a single record for each date, then you could simply merge the calendar table to your customer table and bring in either the fiscal month name (January, February...) or bring in the first date of that fiscal month (you would need that column to exist in your calendar table).

Anonymous
Not applicable

This sounds like a simple option. Do you have any links you can refer me to? I know I can easily create the table.

Announcements

#### Fabric certifications survey

Certification feedback opportunity for the community.

#### Power BI Monthly Update - April 2024

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

#### Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors