Using filter to get Top 5 by Submitted.
However it gives me more than 5, due to duplicates.
How can I tweak or create a measure that would only give me top 5 disregarding duplicates.
I tried to use RANK function but also no success:
Rank = RANKX ( ALLSELECTED ( Policy[CodeDescription] ), CALCULATE ( SUM ( Policy[Submitted]) ) )
You can create a new column and add "Submitted" + RAND() and then rank it based on the new column. Considering you don't have a preference as to which column value gets priority.
Check out the below link for more options:
https://www.red-gate.com/simple-talk/sql/bi/cracking-dax-the-earlier-and-rankx-functions/
I was able to solve it by using below measure:
Top 5 Code filter =
VAR toprank = RANKX(ALLSELECTED(Policy[CodeDescription]), CALCULATE(SUM(Policy[Submitted]) + MAX(Policy[ControlNo]) * 0.0000001),,DESC,Dense)
RETURN
toprank
enter image description here
Below query helped to resolve this issue.
Top 5 Code filter =
VAR toprank = RANKX(ALLSELECTED(gict_riskregisterdetail), CALCULATE(SUM(gict_riskregisterdetail[PICost_RbM_Rnk]) + MAX(gict_riskregisterdetail[Number]) * 0.0000001),,DESC,Dense)
RETURN
toprank
Related
I am using DAX language in Power BI Desktop.
I have a tricky situation where I am trying to use the column name generated from a table variable.
Table 1: SourceTable
Table 2: ReferenceTable
I need to develop a calculated column in SourceTable called EmploymentStatus, based on the corresponding column in ReferenceTable. But I need only the EmploymentStatus value from ReferenceTable, for the maximum InternalID for a given EmployeeEmail.
For example, for the email xyz.gmail.com in SourceTable, I need the EmploymentStatus (calculated column) as 'Active' from ReferenceTable, since 'Active' has the maximum of the two available InternalID values (17, 15).
I tried the following code (Calculated Column in SourceTable):
EmploymentStatus_SourceTable_CalculatedColumn =
VAR tabl1 =
SUMMARIZE (
ReferenceTable,
ReferenceTable[EmployeeEmail],
"MaxInteralID", MAX ( ReferenceTable[InternalID] )
)
VAR tabl2 =
FILTER (
ReferenceTable,
ReferenceTable[InternalID] IN VALUES ( tabl1[MaxInteralID] )
)
VAR NewCol =
LOOKUPVALUE (
tabl2[EmploymentStatus],
tabl2[EmployeeEmail], SourceTable[EmployeeEmail]
)
RETURN
NewCol
I realize that I cannot use the column generated from the table variable.
For example, tabl1[MaxInteralID], tabl2[EmployeeStatus], tabl2[EmployeeEmail] - are all invalid.
Any idea on how to handle this? You can even provide me with a solution that does not use variables at all. Am okay with any solution.
Similar to here, you can find the maximal ID for each email and look up the status for that ID.
Table and column names shortened for readability:
CalcCol =
VAR Email = Source[Email]
VAR MaxID = CALCULATE ( MAX ( Ref[ID] ), Ref[Email] = Email )
RETURN
LOOKUPVALUE ( Ref[Status], Ref[Email], Email, Ref[ID], MaxID )
i need your help calculating following:
based on the region and value(left table), i need to calculate the number of minium values displayed.
For instance, Value 5 is the minium value 3 times. Which function allow me to get that, i'm not able to find a right answer for days.
any idea is welcome!
many thanks
See data as example
Use the following DAX measure to achieve your goal:
CountMinValue=
VAR __value = SELECTEDVALUE( 'Table'[Value] )
Return CALCULATE( COUNT( 'Table'[Min Value]), 'Table'[Min Value] = __value )
I have the requirement in which id# has duplicate records and also has duplicate received_date, where I need to show only unique received date for each id#. Could you please help me on how to resolve this?
Data sample shown below:
I have tried the following in the calculated column
expected_date_or_result =
VAR selected_id = test[id#]
VAR distinct_received_date =
CALCULATE (
FIRSTDATE ( test[received_date] ),
FILTER ( test, test[id#] = selected_id )
)
RETURN
distinct_received_date
I am not sure now to add blanks in case of duplicate received_date.
Please help me with this.
Note: I cannot use remove duplicate option since it is affecting my column group
There are likely many ways to approach this but here's the first one that comes to my mind:
expected_date_or_result =
VAR TopRow =
TOPN (
1,
FILTER ( test, test[id#] = EARLIER ( test[id#] ) ),
test[received_date], ASC,
test[group], ASC
)
RETURN
MAXX (
FILTER ( TopRow, test[group] = EARLIER ( test[group] ) ),
test[received_date]
)
This picks the top row of the table filtered by id# and sorted by received_date and group and then filters that row so that it's only non-empty if the group is the top one and extracts the received_date column using MAXX.
At the beginning I had this table
what I want is to divide the universe into 3 sections, so I do the following
i believe in column
UniqueRank =
RANKX (
inci;
FORMAT (inci[nro_casos]; "0000" ) & inci[region] & inci[site]
)
then I create two measures
ranking_total =
RANKX (
ALLSELECTED ( inci );
inci[UniqueRank];
MAX ( inci[UniqueRank] )
)
tirdh_case = IF(inci[ranking_total]<=COUNTROWS(ALLSELECTED(inci))*0.33;"3P";
IF(inci[ranking_total]<=COUNTROWS(ALLSELECTED(inci))*0.66;"2P";"1P"))
Then I would stay as follows. As you can see, filters of week and region can be applied and normal is divided into three parts, but I want to show it in a graph, and I want to put the tirdh_case as the axis, for this I create a new table called 'axis'
so I create the measure that intersects these two tables
suma_inci = CALCULATE (
SUM( inci[nro_casos] );
FILTER ( inci; [tirdh_case] IN VALUES ('axis'[indice]) )
)
As you can see in the image, the graph works perfectly, but I am inserting the 'site' column as a subcategory, so that when I click on each bar it shows me the sites that belong to that bar, but what happens is that all the sites are accumulate in the first bar ... how would you link the sites and categorize correctly?
This is logical because Measures are dynamically calculated based on your selection. So when you select your bar with the "P1", it needs to recalculate your splitting what is not possible because it is what you select. So if you want to go this level deeper, you need to make your measures a column so it is static divided.
Your column is than like:
tirdh_case =
var maxRank = MAX(inci[UniqueRank])
var splitNr = 3
var divider = maxRank/3
return CEILING((1 + maxRank - inci[UniqueRank])/divider;1) & "P"
You do not need an extra table now because you can use this column as your axis. I made it such that you can change the splitNr to your liking.
End result:
I have got this following SQL query that gives me the correct value from the database.
SELECT
SUM( DISTINCT_ORDER_NUMBERS )
FROM
(
SELECT STORE_KEY,
COUNT( DISTINCT TRANSACTION_NUM ) AS DISTINCT_ORDER_NUMBERS,
DATE_KEY,
TRANSACTION_TYPE_KEY
FROM Pos_Data
GROUP BY STORE_KEY,
DATE_KEY,
TRANSACTION_TYPE_KEY
)
AS A
I am however facing challenges writing a DAX formula for a measure in Power BI Here is what I have tried so far but I get an error.
Total Number Of Orders
VAR _TotalOrders =
SUMMARIZE('Pos_Data',
'Pos_Data'[STORE_KEY],
'Pos_Data'[DATE_KEY],
'Pos_Data'[TRANSACTION_TYPE_KEY],
"DISTINCT_ORDER_NUMBERS",
DISTINCTCOUNT('Pos_Data'[TRANSACTION_NUM]))
RETURN SUM(_TotalOrders[DISTINCT_ORDER_NUMBERS])
Please assist
The SUM function expects a base table rather than a calculated table.
Try this instead:
VAR _TotalOrders =
SUMMARIZE('Pos_Data',
'Pos_Data'[STORE_KEY],
'Pos_Data'[DATE_KEY],
'Pos_Data'[TRANSACTION_TYPE_KEY],
"DISTINCT_ORDER_NUMBERS",
DISTINCTCOUNT('Pos_Data'[TRANSACTION_NUM]))
RETURN SUMX(_TotalOrders, [DISTINCT_CHECK_SEQ])
Edit: If the difference you mentioned is related to nulls, then try this in place of DISTINCTCOUNT.
COUNTAX( DISTINCT( 'Pos_Data'[TRANSACTION_NUM] ), 'Pos_Data'[TRANSACTION_NUM] )
The COUNTAX function (as opposed to COUNTX) does not count nulls.