Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
I'm really new to this. I can't find how to do what's marked with BOLD. I would be very happy if anyone could help med with this:
if [postingDate] >= #date(ThisYear, 1, 1) and [postingDate] <= #date(ThisYear,Thismonth, ThisDay)
then ‘’YTD’’
else if [postingDate] >= #date(ThisYear -1, 1, 1) and [postingDate] <= #date(ThisYear -1,ThisMonth, ThisDay)
then ‘’LYTD’
else ‘’BLANK’’
Solved! Go to Solution.
That is how you do it. The clean code would be something like this @Havard
let
varToday = Date.From(DateTimeZone.FixedUtcNow())
in
if [postingDate] >= Date.StartOfYear(varToday) and [postingDate] <= varToday
then "YTD"
else if [postingDate] >= Date.AddYears(varToday,-1) and [postingDate] <= Date.AddYears(varToday,-1)
then "LYTD"
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI ReportingI Ifinally solved it, but it's bit of .."clumsy". I have seen a code with Let, but don't know how to go from there to if...
if [postingDate] >= Date.StartOfYear(Date.From(DateTimeZone.FixedUtcNow())) and [postingDate] <= Date.From(DateTimeZone.FixedUtcNow())
then "YTD"
else if [postingDate] >= Date.AddYears(Date.From(DateTimeZone.FixedUtcNow()),-1) and [postingDate] <= Date.From(Date.AddYears(Date.From(DateTimeZone.FixedUtcNow()),-1))
then "LYTD"
else "BLANK"
That is how you do it. The clean code would be something like this @Havard
let
varToday = Date.From(DateTimeZone.FixedUtcNow())
in
if [postingDate] >= Date.StartOfYear(varToday) and [postingDate] <= varToday
then "YTD"
else if [postingDate] >= Date.AddYears(varToday,-1) and [postingDate] <= Date.AddYears(varToday,-1)
then "LYTD"
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI ReportingThx a lot! It's easier to see the "language" now.
I thought this worke, but does not. Can somoen pls help me? Im NO good to this;)
if [postingDate] >= Date.StartOfYear(Date.From(DateTimeZone.FixedUtcNow())) and [postingDate] <= Date.From(DateTimeZone.FixedUtcNow())
then "YTD"
else if [postingDate] >= Date.AddYears(Date.From(DateTimeZone.FixedUtcNow()),-1) and [postingDate] <= Date.From(Date.AddYears(Date.From(DateTimeZone.FixedUtcNow()),-1))
then "LYTD"
else "BLANK"
Excellent @Havard - you definitely have the concepts down. Once I figured out how to use variables like this my code got much smaller and easier to edit/read.
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI Reporting