I hope someone can help. I am stuck.
Below are two different DAX functions to calculate my averages.
The first one (Average Coalesce function) gives me the precise results with full data e.g. Q1 & Q2 2022, but it doesn't calculate the quarters correctly as e.g Q3 this year. I do not have data for August/September.
The second Average Connector Usage is not as precise in the result but it calculates the Quarter averages correctly.
It all started with my base function to crete further formulas:
SDR ID average per CP ID =
AVERAGEX(
KEEPFILTERS(VALUES('FACT TABLE'[CP ID])),
CALCULATE(COUNTA('FACT TABLE'[SDR ID]))
)
SDR ID is my unique transaction number and CP ID is my unique location number.
I have tried many measures and these two are the closest to return correct results.
No.1.
Average COALESCE =
IF (
NOT ISEMPTY ( 'FACT TABLE' ),
AVERAGEX (
VALUES ( 'Calendar'[Date] ),
COALESCE ( [SDR ID average per CP ID], 0 )
)
)
No.2.
Average Connector Usage =
IF (
NOT ISEMPTY ( 'FACT TABLE' ),
VAR minDate =
MIN ( 'FACT TABLE'[Start Date] )
VAR maxDate =
MAX ( 'FACT TABLE'[Start Date] )
RETURN
CALCULATE (
AVERAGEX (
VALUES ( 'Calendar'[Date] ),
COALESCE ( [SDR ID average per CP ID], 0 )
),
DATESBETWEEN ( 'Calendar'[Date], minDate, maxDate )
)
)
These are the results.
Date & Connector
Average COALESCE
Average Connector Usage
2022
1.54
2.31
Q2
2.35
2.35
Rapid
2.35
2.35
AC
0.19
0.21
CCS
1.89
1.89
ChaDeMo
0.27
0.28
Q3
0.74
2.19
Rapid
0.74
2.19
AC
0.04
0.27
CCS
0.57
1.68
ChaDeMo
0.13
0.40
Related
How calculate working time eg.
7.5 = 7h and 30 min (working hours)
0.75 = 45 min (pause)
8 = 8h (Planing hours)
How get result eg. (-15 min) below query return 00:15 is it possible get in minus or use have better example?
Select
to_char(time'0:0:0'+numtodsinterval((7.5 + 0.75 - 8 ),'hour'),'hh24:mi')
from dual
You have the arithmetic backwards and to get a negative number you want 8 - (7.5 + 0.75).
Don't use a time and just use the interval (and extract the sign, hour and minute components using string functions if you want a different format):
SELECT numtodsinterval(8 - (7.5 + 0.75),'hour') AS interval,
REGEXP_REPLACE(
numtodsinterval(8 - (7.5 + 0.75),'hour'),
'([+-]?)(\d+) (\d+):(\d+):(\d+\.?\d*)',
'\1\3:\4'
) AS hhmm
FROM DUAL;
Outputs:
INTERVAL
HHMM
-000000000 00:15:00.000000000
-00:15
fiddle
I would appreciate any advises for my problem :
I have a list of stock with daily values (so several stocks and one value per day for each).
I'm trying to do a cumulative margin % on the total portfolio from the beginning of the year as a measure so i have the results on a daily basis.
So by example if the total portfolio value is 100 one day and 102 the day after and 104 the following day, i would like to have a measure with (for these 3 days) 0, 2, 4%.
I have a measure calculating the margin % of the whole portfolio per day (i can't have a column as the data is not portfolio but stock based) :
And what i would like to achieve is the following :
I tried to do a =CALCULATE(sum(dailies[marge_daily_percent_measure]); FILTER(all(dailies);INT(dailies[Date (Year)])=[annee]))
(the filter is to get the current year data) but the sum cannot be applied to the measure (he's looking for a column).
I also tried a TOTALYTD but i then have 2 issues : The Sum still cannot be applied to the measure and i also need the result on a daily basis.
Thanks for any hints.
Assuming your table with stock prices looks like this
Date
Value
30 December 2021
104
31 December 2021
106
03 January 2022
107
04 January 2022
107
05 January 2022
106
06 January 2022
95
07 January 2022
106
10 January 2022
110
I have calculated a Margin measure, DAX below. And cumulative measure using SUMX.
DAX: Margin
Margin =
VAR _SelectedDate =
SELECTEDVALUE ( 'Table'[Date] )
VAR _SelectedValue =
SELECTEDVALUE ( 'Table'[Value] )
VAR _PreviousDate =
CALCULATE ( MAX ( 'Table'[Date] ), 'Table'[Date] < _SelectedDate )
VAR _PreviousValue =
CALCULATE ( SUM ( 'Table'[Value] ), 'Table'[Date] = _PreviousDate )
VAR Margin =
DIVIDE ( _SelectedValue - _PreviousValue, _PreviousValue )
RETURN
Margin
DAX: Margin Cumulative
Cumulative Margin =
VAR _SelectedDate =
SELECTEDVALUE ( 'Table'[Date] )
VAR Cumulative =
CALCULATE (
SUMX ( VALUES ( 'Table'[Date] ), [Margin] ),
'Table'[Date] <= _SelectedDate
)
RETURN
Cumulative
Bear in mind that the final percentage value you get from Cumulative Margin is not the same as the difference from the first value against the last value. In this case, (110-104)/104 = 5.77%. With the Cumulative, I get 6.91%
Output
One way I've built cumulative measures in the past is to do the following logic to filter on date. Assuming you use this in some kind of time-sliced view (like your table, or a linechart), this should only grab the dates on/before 'todays' date for each row.
_Cumulative_ClosedTasks =
CALCULATE (
[_ClosedTasks],
FILTER (
ALL ('Date'[Date]),
'Date'[Date] <= MAX ('Date'[Date])
)
)
([_ClosedTasks] is just a basic SUM metric)
Does this approach work for your data?
I would like to get the no of outlet on volume growth, an outlet is on volume growth if YTD volume > Last YTD volume.
Currently I have two measurements [YTD Volume] and [Last YTD Volume].
How should I write the formula to get the no of outlet on volume growth
No of outlet on volume growth :=
SUMX (
SUMMARIZE (
'Invoice',
[Outlet],
"count", IF ( [YTD Volume] > [Last YTD Volume], 1, 0 )
),
[count]
)
I need to solve a financial math problem. I have a revenue goal set based on target company growth rate. Given this total revenue goal for next year, I need to set sales goals each month that have the growth rate (monthly) applied to them. They will total the annual revenue goal. What this looks like is contributions that increase every occurrence by a set rate. Once I determine either the first or last month's goal, I can discount back or find the future values easily.
The problem I have is that I know what these goals need to total, but not what the first or last goal would equal. Hypothetically, I supposed I could use the mean goal (annual goal/12) to give me the goal for the middle of the year and discount back and scale up from June. However, since there is a growth rate, the compounding causes exponential rather than linear growth of the goals. What kind of formula can I use to solve this? Would I treat this as ongoing (but changing) contributions toward an investment with a set future value and growth rate? Or is there some sort of Goal Solver functionality that will help? I am currently doing this in Google Sheets but can switch to Excel or another medium. (I use R heavily, so not afraid of some programmatic methods).
If I cannot figure this out, I will just apply a linear function to it and use the difference in revenue each year as the slope.
Approach:
Let's assume your business starts in Sep-2017, a Month 0, with S units sold.
The constant growth rate, for each next month, was defined in your Business Case as a q, equal to 8% ( 1.08 )
Month 0: S [units], be it 1, 3 or 76,538,112,257
Month 1: S * q
Month 2: S * q * q
Month 3: S * q * q * q
..
Month 11: S * q * q * q * ... * q
>>> S = 1
>>> q = 1.08
>>> [ S * ( q ** i ) for i in range( 12 ) ]
[ 1.0,
1.08,
1.1664,
1.2597120000000002,
1.3604889600000003,
1.4693280768000005,
1.5868743229440005,
1.7138242687795209,
1.8509302102818825,
1.9990046271044333,
2.158924997272788,
2.331638997054611
]
The S units "Scale-free" sum ( independent on the initial amount )
help determine the relation between the target T units sold in total and any S, given q
>>> sum( [ S * ( q**i ) for i in range( 12 ) ] )
18.977126460237237
Here one can see, how inaccurate would be any attempt to use averages and similar guesses to approximate the progress of the powers of q during the period of compounding a constant growth rate ( yielding a T of ~ 19 x the S over 12 months at a given constant rate q of just 8% -- do not hesitate to experiment with other values of q to see the effect sharper and sharper ).
So for an example of a total T of 19,000 units sold during the Year 0, keeping the growth rate of 8% p.m.:
The initial seed for S would be a target T divided by the sum of ( constant growth ) scaling coefficients:
T / sum( [ S * ( q**i ) for i in range( 12 ) ] )
To be on the safer side,
>>> int( 1 + T / sum( [ S * ( q**i ) for i in range( 12 ) ] ) )
1002
>>> sum( [ 1002 * ( q**i ) for i in range( 12 ) ] )
19015.08 ...
>>> [ int( 1002 * ( q**i ) ) for i in range( 12 ) ]
[ 1002,
1082,
1168,
1262,
1363,
1472,
1590,
1717,
1854,
2003,
2163,
2336
]
Month 0: S ~ 1,002 [units]
Month 1: S * q ~ 1,082
Month 2: S * q * q ~ 1,168
Month 3: S * q * q * q ~ 1,262
.. ~ 1,363
. ~ 1,472
~ 1,590
~ 1,717
~ 1,854
. ~ 2,003
.. ~ 2,163
Month 11: S * q * q * q * ... * q ~ 2,336
_____________________________________________________________
19,012 [unit] per Year 0
So Good Luck & Go Get It Sold!
I need to sum the values of column resulting from the table resulting from Summarize Funtion.
For e.g. my Data Set 'Tab' is like this
Type Value
A 10
A 10
A 10
B 20
B 20
B 20
C 30
C 30
C 30
The result from Summarize(Tab,[Type],AVG([Value])) will be like following
A 10
B 20
C 30
And the final result required from this result set is 10+20+30 i.e. 60.
Please help
You can use SUMX function.
Sum of Avg =
SUMX (
SUMMARIZE ( Tab, [Type], "Total Average", AVERAGE ( Tab[Value] ) ),
[Total Average]
)
It will give you the total if there is not any Type context affecting the measure:
Let me know if this helps.
You need to declare a name for it.
Total Value = Summarize(Tab,'Tab'[Type],"Total value",SUM('Tab'[Value])