Good morning. i have the following fact table
FK_Cmd |FK_Ship |Dilevry_time
C001 |1 |20
C001 |2 |25
C002 |1 |23
i want to calculate the average maximum delivry time per Cmd which would be (25+23)/2 = 24 in the exemple.
i am using the following MDX request :
AVG(MAX([Dim Cmd].[PR_Cmd],[Measures].[Delivery time]))
but i don't get any correct result. can you help with this ? thanks
You would need to define it as a member something like:
WITH MEMBER [Measures].[Max Delivery time] AS Max
([Dim Cmd].[PR_Cmd].currentMember
, [Measures].Delivery time]
)
MEMBER [Measures].[Avg Max Delivery time] AS Avg
([Dim Cmd].[PR_Cmd].allMembers
, [Measures].[Max Delivery time]
)
SELECT [Measures].[Avg Max Delivery time] ON 0
FROM [Cube]
I don't have SSAS currently so I cannot test it but it should be something similar. Another way would be to define it as calculated member in your cube definition if that's important metric for you instead of using MDX every time. It would be faster in the end because the cube will have that value ready for you.
Related
I have created a running total measure in PBI using Dax, however, when the total does not filter by column filter when it is in the table. The running total should sum the balance but then break out into the individual maturity buckets within the table.
Here is the Measure and the resulting table
I have tried adding extra filters using the FILTER/ALL command to break out the maturity buckets and gotten either the same result or errors. Not sure what else I can do?
Here is a fake sample of data. in the comments i have include the language of the measure.
|Date |Tenor|Balance |
|-------------|-----|-----------------|
|December 2022|18m |0.196072326627487|
|December 2022|2y |0.149643186475954|
|December 2022|3y |0.180522608363889|
|December 2022|4y |0.780540306321475|
|December 2022|5y |0.156029893270158|
|January 2022|18m |0.512496934496972|
|January 2023|2y |0.068123785829084|
|January 2023|3y |0.349971677118287|
Here is my solution! I am sorry if I kept you waiting too much!
First, I need to say that your design is not so efficient! You need a full date table with full date values(not only month &year parts)
Here is your calendar table:
Here is the DAX Code you need to write to obtain correct value:
Total_Correct =
CALCULATE (
SUM('Callable'[Balance]),
FILTER ( ALL ( 'Callable'[Date] ), 'Callable'[Date] <= MAX('Callable'[Date])),
ALL('Calendar')
)
I am trying to create a waterfall chart in quicksight with the below dataset format.
I want to multiply the values of specific metrics, for instance if Type = Metric 1 and Metric2, then multiply their respective values, is that feasible using the calculated field option? thanks
**Type | Value**
Metric 1 | 10
Metric 2 | 20
Metric 3 | 30
Here is my measure :
CREATE MEMBER CURRENTCUBE.[Measures].[ContactNumber] AS
nonempty(
UNORDER(
(UNORDER([Contact].[Contact Id].[Contact Id].MEMBERS)
,{linkmember([Period].[Per Quarter].currentmember,[Period Ending].[Per Quarter]).NextMember : STRTOMEMBER('TAIL([Period Ending].[Per Quarter].[' + [Period].[Per Quarter].currentmember.LEVEL.name +'],1)(0)')}
,{NULL :[Period].[Per Quarter].currentmember}
,[Category].[Category].currentmember)
)
,[MAX_BeginDate]
).count
it gives me how much customers there are in a category at a period
my fact table is liked
contact periodin periodout category
A 25 26 cat1
A 26 27 cat2
A 27 end cat3
B 1 26 cat0
B 26 end cat1
C 1 2 cat2
C 3 4 cat2
C 4 end cat3
And my dimensions :
Period regular by periodin
Period ending regular by periodout
contact regular by contact
category regular by category
So for the 26th, I will have :
cat0 0
cat1 1(B)
cat2 1(A)
cat3 1(C)
If someone think to an obvious improvement...
it tooks me over 1min-1min30 for all 4categories in one day of 2017. There are more than 100 million rows in the table fact. Every customer has at least 1fact. Calendar begins in 2000 and there are 60 million of customers.
Thank you
Regards
Antho
Maybe this is faster:
CREATE MEMBER CURRENTCUBE.[Measures].[ContactNumber] AS
SUM(
UNORDER(
(UNORDER([Contact].[Contact Id].[Contact Id].MEMBERS)
,{linkmember([Period].[Per Quarter].currentmember,[Period Ending].[Per Quarter]).NextMember : STRTOMEMBER('TAIL([Period Ending].[Per Quarter].[' + [Period].[Per Quarter].currentmember.LEVEL.name +'],1)(0)')}
,{NULL :[Period].[Per Quarter].currentmember}
,[Category].[Category].currentmember)
),
IIF(
ISEMPTY([MAX_BeginDate])
,NULL
,1
)
)
I think linkmember is a slow function - is there any alternative you can use?
Thank you for answering,
I beleive I already tried replacing the count function by sum without good results.
But as soon as I go back to work I will try your proposition.
Yes I can replace all linkmember by reconstructing every member with level, current member name and strtomember function. It is something I can also try.
I also have the period of customer entry. I use it to know if the customer is "new" at the current period. And maybe it could be possible not browsing all the period dimension from the begining but from the "in period" of the customer...
I am a heavy user of R who is trying to port some basic calculations to Power BI but unable to get DAX to perform vector/rowwise division.
For example, with this dataset:
Category Value
-------- -----
A 1
A 2
B 3
C 4
I have created a measure: Value Sum = SUM(Table[Value])
and I would like to create a third column: Value Share = Value / Value Sum to get:
Category Value Value Share
-------- ----- -----------
A 1 0.1
A 2 0.2
B 3 0.3
C 4 0.4
The equivalent in R would be :
table$Value.Share = table$value/Value.Sum
I have tried: Value Share = [Value] / [Value Sum] but I ended up with 1s in all Value Share rows. Tried SUMX and CALCULATETABLE functions but I believe I am missing something fundamental. Can anyone help?
Sure! If you're starting out with DAX, I can highly recommend to view one of the video lectures of Alberto Cairo / Marco Russo like https://www.youtube.com/watch?v=klQAZLr5vxA, because your question (and all of DAX difficulty) is primarily about contexts.
As for your question, I think you're looking for
=[Value]/CALCULATE(SUM([Value]); ALL(TableName))
Of course, you can replace SUM([Value]) with a measure name too.
See also http://www.daxpatterns.com/cumulative-total/
try this formula: divide([value],sum([value]))
SNAP of DAX formula
I have database where i am calculating the shipping cost. The logic of shipping cost is such way that it is calculated every 500gm. I have price list according to different weight but when i am using calculation taking the weight from user for example 1.4 i am unable to get it to next calculative weight of 1.5 , .7 to 1.0 , 1.7 to 2.0 how to achieve this?
Try this (substitute myNumber to get a different result):
Let (
[
myNumber=2.6;
myNumberInt = INT(myNumber);
myNumberFr = myNumber - myNumberInt;
myNumberFr = Case ( myNumberFr =0;0;myNumberFr >0.5 ; 1;0.5 );
result = myNumberInt + myNumberFr
]
;
result
)
You can wrap it in a custom function, in case you need to change it later throughout the system.
I am sure there is a better mathematical formula, but this should get you started
The Problem is fixed.
I have price list according to weight slab in different table.
I used the Country code with Zone id to track prices for particular weight slab prices provided by the courier company.
The price list for e.g. is in such way :-
Zone 1 .5Kg 100Yuan 1.0Kg 120 yuan etc etc , there goes till 20Kg in some case at max.
so when i input the weight in weight field for e.g. 13.5kg i use this weight / .5 which gives me a value 27 , the reason i use to divide the weight with .5 is for example if i input the weight to 13.8 kg i get 27.6 there upon i embed this in ceiling function in calculation field which gives me value of 28 which i can use to calculate the next price slab in the price list which is for every 500Gms +- .
Once i get this done i use this in script which does the job of going to particular layout to search the zone and the prices and retrieving those data to original layout to show the desired result.
Regards,
Soni