Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.
Check it out now!Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more
Hi all,
n a static table I am adding a calculated column with the following DAX function:
Check FY =
// Check if a date is in current or last FY
VAR CurrentFY =
CALCULATE (
MAX ( Dim_Dates[FY_Val] ),
Dim_Dates[Date] = TODAY (),
ALL ( Dim_Dates )
)
VAR DifFY = Dim_Scen_Auto[FY_val] - CurrentFY
RETURN
SWITCH ( TRUE (), DifFY = 0, "Current FY", DifFY = -1, "Last FY", "" )
As you can see it is adding a description if a Fiscal Year is "Current FY" or "Last FY" and behaves exactly as expected. For several reasons I would like to have this column added via PQ rather than via DAX but I am struggling in the conversion.
Is this doable in a simple way?
Many thanks in advance,
C.
Solved! Go to Solution.
Hi @Anonymous ,
You can try the following expression:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtE11DVUitUBc4x1DY10jdG4BjAuSKkRipyRpVJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Year = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", type date}}),
#"Inserted Year" = Table.AddColumn(#"Changed Type", "Year.1", each Date.Year([Year]), Int64.Type),
#"Added Custom" = Table.AddColumn(#"Inserted Year", "Custom", each let
CurrentDateTime = DateTime.LocalNow(),
CurrentYear = Date.Year(CurrentDateTime),
result = if CurrentYear-[Year.1]=0 then "Current FY" else if CurrentYear-[Year.1]=1 then "Last FY" else ""
in
result)
in
#"Added Custom"
An attachment for your reference. Hope it helps!
Best regards,
Community Support Team_ Scott Chang
If this post helps then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Anonymous ,
You can try the following expression:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtE11DVUitUBc4x1DY10jdG4BjAuSKkRipyRpVJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Year = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", type date}}),
#"Inserted Year" = Table.AddColumn(#"Changed Type", "Year.1", each Date.Year([Year]), Int64.Type),
#"Added Custom" = Table.AddColumn(#"Inserted Year", "Custom", each let
CurrentDateTime = DateTime.LocalNow(),
CurrentYear = Date.Year(CurrentDateTime),
result = if CurrentYear-[Year.1]=0 then "Current FY" else if CurrentYear-[Year.1]=1 then "Last FY" else ""
in
result)
in
#"Added Custom"
An attachment for your reference. Hope it helps!
Best regards,
Community Support Team_ Scott Chang
If this post helps then please consider Accept it as the solution to help the other members find it more quickly.
Hi @v-tianyich-msft ,
your solution works perfectly and helped a lot pointing me to the solution and to a better understanding of M. As my Fiscal Year does not match Calendar Year (it goes from Dec to Nov) I just had to apply a small change to your code as below:
= Table.AddColumn(#"Added Custom6", "Check FY", each let
CurrentDateTime = DateTime.LocalNow(),
CurrentYear = Date.Year(CurrentDateTime)-2000,
CurrentFY = if Date.Month( CurrentDateTime ) = 12 then CurrentYear+1 else CurrentYear,
result = if CurrentFY-[FY_val]=0 then "Current FY" else if CurrentFY-[FY_val]=1 then "Last FY" else ""
in
result)
Thanks, you made my day!
Regards,
C.
You would have to show the relevant fragment of your Power Query table and indicate what your fiscal year boundaries are.
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information or anything not related to the issue or question.
If you are unsure how to upload data 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.
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...