The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I have a Sub Date column that simply has dates: 1/1/2020, 1/16/2020, etc. I want to add a custom column in the query that checks IF the date is between first of the month to the 8th of the month, and if so, set value to either TRUE or 1 to signify it's within that date range
How can I achieve this in M?
Solved! Go to Solution.
Hi, @Anonymous
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
You may add a custom column with the following m codes.
=if Date.Day([Sub Date])>=1 and Date.Day([Sub Date])<=8
then 1 else 0
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @Anonymous
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
You may add a custom column with the following m codes.
=if Date.Day([Sub Date])>=1 and Date.Day([Sub Date])<=8
then 1 else 0
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello @Anonymous ,
Please find the steps to achieve the result in query editor.
let
Source = Excel.Workbook(File.Contents("C:\Users\kgawale\Documents\Test 15 March 2021.xlsx"), null, true),
Sheet7_Sheet = Source{[Item="Sheet7",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Sheet7_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Contract Date", type date}}),
#"Inserted Month" = Table.AddColumn(#"Changed Type", "Month", each Date.Month([Contract Date]), Int64.Type),
#"Added Conditional Column" = Table.AddColumn(#"Inserted Month", "Custom.1", each if [Month] <= 8 then 1 else 0)
in
#"Added Conditional Column"
User | Count |
---|---|
77 | |
75 | |
36 | |
31 | |
28 |
User | Count |
---|---|
106 | |
98 | |
55 | |
49 | |
48 |