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 September 15. Request your voucher.
Hello community! It is a pleasure to be part of this group! I am going crazy with creating a function and I need a little help since
I hardly know the M language.I have two fields, one with dates that come to me from the database and another with holidays, which
I need is to create a loop with a counter initialized to zero that works on the dates field and compares the dates, if it does not
find them, it should put a 0. When it finds a match it should restart the loop and if the later date is not a holiday ( do not match),
put a one, and if it also matches, restart the loop until it exits and adds the number of consecutive holidays (Rarely more than 2).
Can this be done? I'm going to have problems with my boss but ... hahahaha Thank you very much!
Solved! Go to Solution.
I think your English is very good. You can keep the column you have now and use it in a new column using this approach. Adapt for your table/column names. You could consolidate the two expressions, but hopefully this works for you (and you'll have both columns for different types of calculations).
Days Til Next Workday =
VAR vThisDate = 'Date'[Date]
VAR vNextWorkday =
CALCULATE (
MIN ( 'Date'[Date] ),
'Date'[Date] > vThisDate,
'Date'[IsWorkingDay] = 0
)
RETURN
DATEDIFF (
vThisDate,
vNextWorkday,
DAY
)
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
I think your English is very good. You can keep the column you have now and use it in a new column using this approach. Adapt for your table/column names. You could consolidate the two expressions, but hopefully this works for you (and you'll have both columns for different types of calculations).
Days Til Next Workday =
VAR vThisDate = 'Date'[Date]
VAR vNextWorkday =
CALCULATE (
MIN ( 'Date'[Date] ),
'Date'[Date] > vThisDate,
'Date'[IsWorkingDay] = 0
)
RETURN
DATEDIFF (
vThisDate,
vNextWorkday,
DAY
)
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
I expect this can be done, but it I'm not totally clear on what you need. Please post some sample date values (in a copy/paste format, not an image) and indicate what the correct output would be.
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Thank you very much for answering! Obviously I explained badly (And my English is surely very bad too), the problem is the following: I have two tables with fields. In one I have the dates of the whole year, and in another the dates of the holidays. What I need is to identify the holidays and weekends and add them in a loop. To make it better understood, I work in a logistics company, so when a package arrives on a Friday (For example) and assuming that Monday is a holiday, I need a line that marks a 3 for me, since I would have three non-working days since the package arrived. In the photo you can see that I made a function that detects holidays and weekends, but what I really need (as the annotations in the image show) is for the function to be included in a loop, so that it can iterate and accumulate the holidays and weekends that I have each time a package arrives. Hopefully my problem has been understood a little better! From already thank you very much !