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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
James_Ma
Helper I
Helper I

Populate a date field based on a criteria

Hi ,

 

I have a bit of a dilema regarding creation of a new date field based on two otehr date fields values.

 

For example - If i have an item with a billing date set to 30th September 2023 and alos has a billing entered date set to the 1st or 2nd day for October I need the allocation date to be set to the billing date.

 

If the billing date is 30th September and the billing entered date is 20th September, then the allocated date should be the 30th Sept

 

However if the billing date is the 30th September 2023 and the billing entered date is 4th October 2023 then the allocated date should be 4th October.

 

Basically ther are 2 days at the beginning of each month whereby billing entered dates can be added for itmes with billing dates in the  previous month

Billing dateBilling entered dateAllocation date (non calculated value)
28/10/202301/11/202328/10/2023
28/10/202302/11/202328/10/2023
30/09/202320/09/202330/09/2023
29/09/202304/10/202304/10/2023
01/02/202302/02/202301/02/2023
4 REPLIES 4
lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMrLQNzTQNzIwMlbSUTIw1Dc0hHBiddDljFDkjA30DSxhckYIDlifJZKcgQncEJAc0AqgSQgzYZzYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Billing date" = _t, #"Billing entered date" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Billing date", type date}, {"Billing entered date", type date}},"en-GB"),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Allocation date", each if List.Contains({1,2},Date.Day([Billing entered date])) then [Billing date] else List.Max({[Billing date],[Billing entered date]}))
in
    #"Added Custom"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

Thanks for this, the problem is that the data  I gave are just for a a demo purpose, not the actual data table

 

Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue.
If you are unsure how to do that please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.

If you want to get answers faster please refer to https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Guess the below is the same as above right?

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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