Get certified for free when you join Fabric Data Days 2026 and dive into Fabric, Power BI, SQL, AI, and other essential data skills.
Join nowData Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more
Dear BI community. Once again I ask your kind help with the following issue: I have a table which contains a team description, a date, a test result and a region for every purchaser. I'm trying to create a custom function so that I can invoke it every time I want on any query. It is a really complex function but in order to sum up, the purchaser that meets the following 3 conditions gets the price:
1. The team must be either "A" or the test result must be different to "Negative".
2. The date must be between january and june.
3. The region must be either "Center" or "East Coast".
The table looks as follows: The purchasers that would receive the prize are 1, 3, 8 and 11. Below you can see the table and the code I'm trying to use. I've tried with && and ‖, but it doesn't work either. I'd really appreciate your help guys!!. Thanks.
let
SuperFunction= (Team,Date,Region,Test) =>
if Team = "A" Or (Test <> "Negative") and (Date>= 1/1/2016 and Date<=6/1/2016) and (Region = "Center" or Region = "East Coast") then "Gets Prize" else
"Doesn't get Prize"
in
SuperFunction
As I told you before, I'd like to be able to invoke the function, from a query and choose the parameters.
Solved! Go to Solution.
In general, and has a higher priority than or.
The keywords if, then, else, and, or are all lowercase.
For date values, the function #date must be used.
Based on these rules, my suggestion would be:
let
SuperFunction= (Team as text, Date as date, Region as text, Test as text) =>
if (Team = "A" or Test <> "Negative") and Date>= #date(2016,1,1) and Date<=#date(2016,6,1) and (Region = "Center" or Region = "East Coast") then "Gets Prize" else
"Doesn't get Prize"
in
SuperFunction
I would expect < #date(2016,6,1) instead of <= #date(2016,6,1), so June 1, 2016 would be excluded.
In general, and has a higher priority than or.
The keywords if, then, else, and, or are all lowercase.
For date values, the function #date must be used.
Based on these rules, my suggestion would be:
let
SuperFunction= (Team as text, Date as date, Region as text, Test as text) =>
if (Team = "A" or Test <> "Negative") and Date>= #date(2016,1,1) and Date<=#date(2016,6,1) and (Region = "Center" or Region = "East Coast") then "Gets Prize" else
"Doesn't get Prize"
in
SuperFunction
I would expect < #date(2016,6,1) instead of <= #date(2016,6,1), so June 1, 2016 would be excluded.
Sir, once again, you saved my life!!! Thanks, I guess I'm used to thinking like Excel and there's a long way to master "M" language. I didn't declare variables and I was forgetting about the lowercase. Anyway, I really find this kind of functions really useful for users like I, who don't have any access to complex data bases and need to create this kind of functions in PQ.
Thanks sir!
Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.
Check out the May 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 23 | |
| 23 | |
| 21 | |
| 20 | |
| 15 |
| User | Count |
|---|---|
| 58 | |
| 53 | |
| 42 | |
| 30 | |
| 24 |