Power query variable

dicken

Active Member
Joined
Feb 12, 2022
Messages
292
Office Version
  1. 365
Platform
  1. Windows
HI,
is it possible to declare a variable in the add custom column dialog of power query so ;
Financial quarter:

if Date.QuarterOfYear([#"Date "]) - 1 = 0 then 4 else
Date.QuarterOfYear[#"Date "]-1 ,

so in dax VAR abc = "Quarter"
RETURN if ( "Quarter"-1 = 0, 4 , "Quarter )

Or somthing similar, I think I have done this at some point but can't remember how, whether I had to use a let statemnt ?

Richard
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Yes in PQ in the editor before the source line simply type
Power Query:
Let
VarableName = 1,
you can then use this variablename in your custom column
 
Upvote 0
if it is the dates i normally just do as follows in Adv Editor
Power Query:
let
Quarter ={3,3,3,4,4,4,2,2,2,1,1,1},
then in my custom column (Fiscal Qtr) add formula as
=Quarter{Date.Month([Date]-1}

Which i guess is what you may be trying to achieve but entering your "if" statement to check if the above is =0
 
Upvote 0
Solution
if it is the dates i normally just do as follows in Adv Editor
Power Query:
let
Quarter ={3,3,3,4,4,4,2,2,2,1,1,1},
then in my custom column (Fiscal Qtr) add formula as
=Quarter{Date.Month([Date]-1}

Which i guess is what you may be trying to achieve but entering your "if" statement to check if the above is =0
 
Upvote 0
Hi,
Just to update this is what I wanted, if you have a better way please share, I find the use of 'in', also if delcaring multible variables,
so if i have this which works fine,
Excel Formula:
let QuartF = 
Number.RoundUp(  ( Date.QuarterOfYear([Date] ) / 3 ) ) -1 
in 
if
QuartF = 0 then 4 else QuartF
,


but wanted to break it down;


l
Excel Formula:
et QuartF = 
Number.RoundUp(  ( Date.QuarterOfYear([Date] ) / 3 ) ) 

let minuseone = QuartF -1 

in  if  minusone -= 0 , 4, miunsone.
, the second let is always an error, I've tried commas , no commas etc , any suggestoins.

Richard.
 
Upvote 0
Hi,
Just to update this is what I wanted, if you have a better way please share, I find the use of 'in', also if delcaring multible variables,
so if i have this which works fine,
Excel Formula:
let QuartF =
Number.RoundUp(  ( Date.QuarterOfYear([Date] ) / 3 ) ) -1
in
if
QuartF = 0 then 4 else QuartF
,


but wanted to break it down;


l
Excel Formula:
et QuartF =
Number.RoundUp(  ( Date.QuarterOfYear([Date] ) / 3 ) )

let minuseone = QuartF -1

in  if  minusone -= 0 , 4, miunsone.
, the second let is always an error, I've tried commas , no commas etc , any suggestoins.

Richard.
The penny has dropped think I've got how it work, of course the pq 'if' statment doesn't help, all this 'then' or 'else' I keep hitting comma out of habit,

Excel Formula:
let 
Frac =Number.RoundUp( Date.QuarterOfYear([Date]) / 3),
minusone = Frac - 1, 
anser = if minusone = 0 then 4 else minusone 
in 
 anser
 
Upvote 0

Forum statistics

Threads
1,223,631
Messages
6,173,465
Members
452,516
Latest member
archcalx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top