Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I`m trying to adjust the following formula after the column type I am using changed from date to Numeric.
Here is the previous calcualtion - which is working fine:
Solved! Go to Solution.
Hi @Anonymous
Please try
Target =
VAR CurrentNew =
MAX ( 'metrics'[New] )
VAR T2 =
CALCULATE ( SUM ( metrics[Sales] ), 'metrics'[New] = CurrentNew + 2 ) * 0.1
VAR T_2 =
CALCULATE ( SUM ( metrics[Sales] ), 'metrics'[New] = CurrentNew - 2 ) * 0.1
RETURN
COALESCE ( T2, T_2 )
Hi @Anonymous
Please try
Target =
VAR CurrentNew =
MAX ( 'metrics'[New] )
VAR T2 =
CALCULATE ( SUM ( metrics[Sales] ), 'metrics'[New] = CurrentNew + 2 ) * 0.1
VAR T_2 =
CALCULATE ( SUM ( metrics[Sales] ), 'metrics'[New] = CurrentNew - 2 ) * 0.1
RETURN
COALESCE ( T2, T_2 )
@tamerj1
Thank you, it works like a charm.
An additional question I have, why doesn`t the measure work if I place it on another chart with a different x-axis?
I`m replacing the [New] column on this new chart with a text field [New FY] that has 1 to 1 values as such in the same table:
1 FY1
2 FY2
3 FY3
@Anonymous
Please try?
Target =
VAR CurrentNew =
MAX ( 'metrics'[New] )
VAR T2 =
CALCULATE (
SUM ( metrics[Sales] ),
'metrics'[New] = CurrentNew + 2,
ALL ( 'metrics' )
) * 0.1
VAR T_2 =
CALCULATE (
SUM ( metrics[Sales] ),
'metrics'[New] = CurrentNew - 2,
ALL ( 'metrics' )
) * 0.1
RETURN
COALESCE ( T2, T_2 )
@tamerj1
Works perfectly, I just changed ALL to ALLSELECTED cause I have some filters applied.
Many thanks
Hi @Anonymous,
If you are using a numeric field instead of a date field in your formula, you cannot use the DATEADD function to add or subtract years from the value in the column. Instead, you need to use a mathematical operation to subtract the appropriate number of years from the value in the column.
Assuming your numeric field is called 'New', the adjusted formula should be:
Target =
VAR T = CALCULATE(SUM(metrics[Sales]), 'metrics'[New] + 2)*0.1
RETURN IF(T <> 0, T, CALCULATE(SUM(metrics[Sales]), 'metrics'[New] - 2)*0.1)
In this formula, we use the plus and minus operators to add or subtract the number of years from the value in the 'New' column. Note that we use single quotes around the column name, as we are referring to a column in the same table.
I hope this helps!
Best regards,
Isaac Chavarria
If this post helps, then please consider Accepting it as the solution and giving Kudos to help the other members find it more quickly.
Thanks Isaac.
The issue I`m facing with the formula is that it`s returning the value as if we are not subtracting or adding 2.
Sample data and results vs required results are:
New Sales Target Desired Values of Target
1 20 2 6
2 40 4 8
3 60 6 10
4 80 8 4
5 100 10 6
User | Count |
---|---|
25 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
26 | |
12 | |
11 | |
8 | |
7 |