SSAS Tabular - DAX Dynamic Ranking measure with slicer - ranking

I'm searching for a measure to utilize within SSAS Tabular model that will me to perform dynamic ranking that will automatically update the associated rank value based on filters and slicer values that are applied.
I am not in this kind of scearios : PowerPivot DAX - Dynamic Ranking Per Group (Min Per Group)
The difference is the following, my data are not in the same table :
I have a fact table like this :
-------------------------------------------------------------------------------------
ClientID | ProductID | Transaction Date | Sales
------------------------------------------------------------------------------------
C1 P3 1/1/2012 $100
C2 P1 8/1/2012 $150
C3 P4 9/1/2012 $200
C1 P2 3/5/2012 $315
C2 P2 9/5/2012 $50
C3 P2 12/9/2012 $50
------------------------------------------------------------------------------------
A Customer table
-------------------------------------------------------------------------------------
ClientID | ClientCountry |
C1 France
C2 France
C3 Germany
------------------------------------------------------------------------------------
...and also a Product table
-------------------------------------------------------------------------------------
ProductID | ProductSubCategory |
P1 SB1
P2 SB1
P3 SB2
P4 SB3
------------------------------------------------------------------------------------
So here is my visualization pivot table :
-------------------------------------------------------------------------------------
ProductSubCategory | Sales
SB1 565 (150 + 315 + 50 + 50)
SB2 100
SB3 200
And the measure I'm looking for should perform like this :
-------------------------------------------------------------------------------------
ProductSubCategory | Sales | Rank
SB1 565 (150 + 315 + 50 + 50) 1
SB2 100 3
SB3 200 2
...simple, I browse my cube into Excel, put the ProductSubCategory in line, sum of Sales and expect my measure gives me correct ranking by ProductSubCategory.
Now, scenario also includes using a slicer on ClientCountry.
So when I select 'France', I expect my measure gives me an adapted ranking, only including ProductSubCategory for Clients living in France (so C1 and C2).
I tried a lot of solutions but without any result. Has anyone and idea with this kind of scenario ?
I greatly appreciate your help with this!
Thank's all

Related

Elasticsearch - Sum by quantity and sort by lowest price

I have a requirement in Elasticsearch which I'm not able to implement at the moment. The use case is as follows; we have certain products uploaded in elastic (1 million + items) and each item has a quantity, a price and a lead time (for delivery).
Now I basically want to get the top matches (based on a product description search) where tot sum of all quantities = 1000 (example) sorted by the lowest price.
A similar but other query would be to get the top 1000 items with the lowest lead time.
Any recommendation on how to implement this and what the most performant way of doing this is?
Assume we have the following records:
Product 1 | Quantity 200 | price 4USD | lead time 2 days
Product 2 | Quantity 150 | price 3USD | lead time 5 days
Product 3 | Quantity 275 | price 5 USD | lead time 14
Now I want to get all products for a maximum of quantity of 200 with the cheapest items first. That would give me something like:
Product 2
Product 1
And then it would also give me some aggregates like the average delivery time for these 2 items is 3.5 days and total value is 650USD (150 x 3USD + 50 x 4 USD)
Thanks,
Bram

DAX grand total "wrong" for price variance

I have repeatedly ran into the following problem when calculating variances, that the grand totals are calculated wrong. Although they are not technically wrong, I want to calculate them differently. The picture below shows what I have constructed in PowerPivot.
Formulas:
ACT Sales EUR = CALCULATE([Sales EUR];FILTER(data;data[Type] = "ACT"))
ACT Sales/kg = DIVIDE([ACT Sales EUR];[ACT Sales KG])
FC Sales/kg = DIVIDE([FC Sales EUR];[FC Sales KG]
Quantity Variance = ([ACT Sales KG] - [FC Sales KG]) * [FC Sales/kg]
Price Variance = ([ACT Sales/kg] - [FC Sales/kg]) x [ACT Sales KG]
The total variance is equal to column [Sales ACT vs FC EUR], but I would like the grand total for the variances to be a simple sum of the rows, and not using the measure formula on the grand total. How should this be done correctly?
The column structure for the data is as follows (where Type is either ACT, BUD, FC):
| Date | Type | Product | EUR | KG |
To fix variance totals, you need to iterate over product and then sum up the results:
Quantity Variance = (
SUMX(
VALUES( Data[Product]),
[ACT Sales KG] - [FC Sales KG]) * [FC Sales/kg]
)
(same for the other variance)

PowerBI DAX Rank basis filtered Measure

I have sales table wherein we have attributes like Store Name, Sales and row level measure of Index Value.
I need to filter the table basis index value (greater than 0.0) and then compute rank in ascending order of Index Values
STORE NAME | Sales | Index Value
A | 10 | 0.5
B | 15 | 0.4
C | 15 | 0
So here, my output should contain rank of stores A,B only(2,1) and not C
PS Note: Index Value is a calculated measure
Based on your sample data,seems like you need the rank order Descending
Use the below
IndexRank = RANKX(ALL(Sales),[Index Value]>0.0,,DESC,Dense)

DAX running total + starting value

I am fairly new to the DAX universe, but scrolling around I managed to successfully implement a cumulative (running) total, with a measure defined along this structure: Running_Total_QTY:=CALCULATE(SUM(Reporting[QTY]),FILTER(ALL(Reporting[DATE_R]),Reporting[DATE_R]<=MAX(Reporting[DATE_R])))
For a table that looks like this:
ID DATE_R QTY
A1 5/11/2018 9:00 5
A1 5/11/2018 9:01 10
A1 5/11/2018 9:01 -5
A1 5/11/2018 9:02 50
A1 5/11/2018 9:05 -20
B1 5/11/2018 9:00 3
B1 5/11/2018 9:01 -20
B1 5/11/2018 9:01 4
B1 5/11/2018 9:02 20
B1 5/11/2018 9:03 10
The problem is that I would need to add to this running total a starting QTY - QTY_INIT, which I receive from another table that looks like this:
ID1 QTY_INIT
A1 100
B1 200
By trial and error I have succeeded by creating a second measure that calculates the average (of 1 item!) defined like this:
Average_starting_quantity:=CALCULATE(AVERAGE(Starting_Quantity[QTY_INIT]),FILTER(ALL(Starting_Quantity[ID1]),Starting_Quantity[ID1]=LASTNONBLANK(Reporting[ID],TRUE())))
And then just adding the two measures together.
Running_plus_total:=[Running_Total_QTY]+[Average_starting_quantity]
This method works, but is very inefficient and very slow (the data set is quite big).
How can I add QTY_INIT from the second table directly without using a "fake" average (or max, min, etc..)? How can I optimize the measure for a faster performance?
Thanks in advance for any help.
Regards
How about this instead of your Average_starting_quantity?
StartingQty = LOOKUPVALUE(Starting_Quantity[QTY_INIT],
Starting_Quantity[ID1], MAX(Reporting[ID]))
If your tables are related on ID and ID1 with cross filter direction going both ways,
then you can just use
StartingQty = MAX(Starting_Quantity[QTY_INIT])
since the filter context on ID will flow through to ID1.

How to do Pivoting in Oracle 10g

Consider the following
Sample Input
SalesBoyName Product Amount
------------ ------- ------
Boy1 P1 100
Boy1 P1 40
Boy1 P2 100
Boy2 P1 100
Boy2 P3 12
Desired Output
SalesBoyName P1 P2 P3
------------ ---- ---- ----
Boy1 140 100 null
Boy2 100 null 12
The below SQL SERVER 2005 query will do the work
SELECT SalesBoyName, [P1] AS P1, [P2] AS P2,[P3] AS P3
FROM
(SELECT * FROM tblSales ) s
PIVOT
(
SUM (Amount)
FOR Product IN
( [P1], [P2], [P3])
) AS pvt
I want to perform the same thing in Oracle 10g.
How to do this?
This may be trivial, but since i am very new to Oracle, so I am seeking for help.
Thanks
You can do it like this in 10G:
select salesboyname,
sum (case when product='P1' then amount end) as p1,
sum (case when product='P2' then amount end) as p2,
sum (case when product='P3' then amount end) as p3
from tblsales
group by salesboyname;
In 11G there is a PIVOT keyword similar to SQL Server's.

Resources