PowerBI Dax Query - To find invoice which never had success state - powerbi

I have to find the count of invoices that never went to a successful state at all. I tried checking multiple sites but not able to understand and recreate the query. Kindly help me. Thanks in advance.
In the above sample invoice 14 never went to success state. So the InvoiceCount = 1 and UniqInvoice count is 2.
I want the uniqInvoice count from the above table.

Create a Custom Column and a Measure as below to achieve your required output-
Custom Column-
success_check =
var current_row_invoice = your_table_name[invoice]
var count_success =
CALCULATE(
COUNT(your_table_name[invoice]),
FILTER(
ALL(your_table_name),
your_table_name[invoice] = current_row_invoice
&& your_table_name[status] = "S"
)
)
RETURN IF(count_success>=1, 1,0)
Measure-
unique_count =
CALCULATE(
DISTINCTCOUNT(your_table_name[uniqinvoice]),
FILTER(
your_table_name,
your_table_name[success_check] = 0
)
)
Here is the output-

I finally found a way to frame the Dax Query, Hoping it will help someone.
FC = CALCULATE (
DISTINCTCOUNT ( InvoiceTable[UniqInvoice] ),
FILTER (
InvoiceTable,
NOT (
InvoiceTable[Invoice]
IN SELECTCOLUMNS (
FILTER (
SUMMARIZE ( InvoiceTable, InvoiceTable[Invoice], InvoiceTable[Status] ),
InvoiceTable[Status] = "S"
),
"InvoiceNo", InvoiceTable[Invoice]
)
)
)
)

Related

Calculating Max value of a measure in DAX

I Need to calculate the Max value from a measure. Below is the scenario.
Expectation : Pareto%* column should return max value from RunningTotal* Measure which is 1982. Each row in Pareto%* should return 1982.
DAX which I tried:
DAX for Pareto%*
Pareto%* =
MAXX(ALL(EventDetail[TimelinessBreak]),[RunningTotal*])
Can anyone please suggest what is wrong with the above DAX.
[![enter image description here][2]][2]
DAX suggested by Marcus returning 3587177 which is incorrect.
Test34* =
CALCULATE (
[RunningTotal*] ,
ALL ( EventDetail )
)
Description for [RunningTotal*]
CALCULATE(
[ActualUpdates],
FILTER(
CALCULATETABLE(
SUMMARIZE(
'EventDetail',
'EventDetail'[TimelinessBreakSort],
'EventDetail'[TimelinessBreak]
),
ALLSELECTED('EventDetail')
),
ISONORAFTER(
'EventDetail'[TimelinessBreakSort], MAX('EventDetail'[TimelinessBreakSort]), DESC,
'EventDetail'[TimelinessBreak], MAX('EventDetail'[TimelinessBreak]), DESC
)
)
)
If I remove the timelinessbreak column from the table it is showing correct output with my DAX.
With the added information, I suggest:
Pareto%* =
MAXX (
SUMMARIZE (
ALL ( EventDetail ) ,
EventDetail[TimelinessBreak] ,
EventDetail[TimelinessBreakSort]
) ,
[RunningTotal*]
)
You can also try this (like your original measure), which is a bit more compact:
Pareto%* =
MAXX (
ALL (
EventDetail[TimelinessBreak] ,
EventDetail[TimelinessBreakSort]
) ,
[RunningTotal*]
)
Try:
I might be mistaken, though due to your definition of RunningTotal* you may have to use SUMMARIZE here:
=VAR T1 =
SUMMARIZE(
ALLSELECTED( EventDetail ),
EventDetail[TimelinessBreak],
"Running Total", [RunningTotal*]
)
RETURN
MAXX(
T1,
[Running Total]
)

Is there any DAX Measure that Count rows that have an ID matching another row, but a different value in the column

I have a table with ID and with different statuses but some are not having both. I need create measure that will give the count for all the ID's that are having different statues.
I have tried below Dax functions but not giving the expected results.
Link-EC-Count =
VAR count_Donor =
CALCULATE (
DISTINCTCOUNT ( MagentaBuilt_Linked[Microwave IQ Link ID] ),
FILTER (
ALLEXCEPT ( MagentaBuilt_Linked, MagentaBuilt_Linked[Microwave IQ Link ID] ),
MagentaBuilt_Linked[Site_Nature] = "Donor"
),
FILTER (
MagentaBuilt_Linked,
MagentaBuilt_Linked[Primary AAV Vendor] = "T-Mobile"
)
)
VAR count_Recepient =
CALCULATE (
DISTINCTCOUNT ( MagentaBuilt_Linked[Microwave IQ Link ID] ),
FILTER (
ALLEXCEPT ( MagentaBuilt_Linked, MagentaBuilt_Linked[Microwave IQ Link ID] ),
MagentaBuilt_Linked[Site_Nature] = "Recipient"
),
FILTER (
MagentaBuilt_Linked,
MagentaBuilt_Linked[Primary AAV Vendor] = "T-Mobile"
)
)
RETURN
IF ( count_Donor > 0 && count_Recepient > 0, 1, 0 )
Here is the sample data looks like
Anybody have any ideas?
Here's a calculated column formula for "Eligible Row?" that works:
Eligible Row? =
IF(
CALCULATE(
COUNTROWS('Table'),
FILTER('Table',
'Table'[Affiliate ID]=EARLIER('Table'[Affiliate ID]) &&
'Table'[Achievement Type] <> EARLIER('Table'[Achievement Type])))>0,
"Yes","No")
The idea is to filter the table for rows when the Affiliate ID matches, then filter for rows where the Achievement is different, then count the rows.
Here are formulas for my two intermediate calculated columns:
Count ID =
CALCULATE(
COUNTROWS('Table'),
FILTER('Table',
'Table'[Affiliate ID]=EARLIER('Table'[Affiliate ID])))
Count Other Achievements =
CALCULATE(
COUNTROWS('Table'),
FILTER('Table',
'Table'[Affiliate ID]=EARLIER('Table'[Affiliate ID]) &&
'Table'[Achievement Type] <> EARLIER('Table'[Achievement Type])))
I think This is what you need. Try this code as measure:
Count ID =
VAR TblSummary = ADDCOLUMNS(
SUMMARIZE('Sheet 1','Sheet 1'[Affiliate Id],'Sheet 1'[Achievement Type]),
"UniqueCount",CALCULATE(COUNT('Sheet 1'[Affiliate Id]),ALLEXCEPT('Sheet 1','Sheet 1'[Affiliate Id]))
)
RETURN
SUMX(TblSummary,IF([UniqueCount]>1,[UniqueCount]))
If we test it on a visual:

Summarize and remove any rows which has a blank total

I have written a DAX code which returns names of individuals with a count of how many customers they own, however what I need to do is only retrieve the names or essentially filter out the names who have a blank total, how would I go about this as I have tried everything
summarizedCAM =
SUMMARIZE (
d_cam,
d_cam[name],
"Total", DISTINCTCOUNT(ftm[p_key])
)
Current Output:
summarizedCAM =
FILTER(
SUMMARIZE (
d_cam,
d_cam[name],
"Total", DISTINCTCOUNT(ftm[p_key])
)
,ISBLANK([Total])=FALSE()
)
try like this :
Modelling --> New Table
summarizedCAM =
VAR _tbl =
SUMMARIZE ( d_cam, d_cam[name], "Total", DISTINCTCOUNT ( ftm[p_key] ) )
RETURN
FILTER ( _tbl, [Total] > 0 )

Power BI- Query Edit

I am trying to create new measures that will only show the data value of the Last day every month and another measure will show the data value of every week Saturday in Power BI.
Many thanks in Advance.
The data is continuing and the next series of data will appended data wise
Output:
Need to create a measure which will show only last day of the Week value ( Example- Saturday is my Last of the Week and Count numbers I need to see as output)
Similarly for Month - Last day of the Month I need to see the Numbers of each service.
Do you have Calendar table mark as "Date Table", which is connected by relationship to your Table? If so, then you can use ENDOFMONTH ( 'Calendar'[issue_date] ) to get lastDateOfMonth
then simply:
ShowValueAtLastDayOfMonth =
calculate( sum(Table[Total sale]),
KEEPFILTERS(
filter(ALL('Calendar'[issue_date]),
'Calendar'[issue_date] = ENDOFMONTH ( 'Calendar'[issue_date] )
)
)
)
ShowOnlyOnSaturday =
calculate(sum(Table[Total sale]), KEEPFILTERS( FLITER(ALL('Calendar[issue_date]),
WEEKDAY ( SELECTEDVALUE('Calendar'[issue_date])) = 7 )))
Without a "Date Table" we need to replace 'Calendar'[issue_date] with your Table[Date] and ENDOFMONTH with:
VAR LastDateVisible =
CALCULATE ( MAX ( 'Table'[Date] ) )
VAR LastYearVisible =
YEAR ( LastDateVisible )
VAR LastMonthVisible =
MONTH ( LastDateVisible )
VAR DaysInMonth =
FILTER (
ALL ( 'Table'[Date] ),
YEAR ( 'Table'[Date] ) = LastYearVisible
&& MONTH ( 'Table'[Date] ) = LastMonthVisible
)
VAR LastDayInMonth =
MAXX (
DaysInMonth,
'Table'[Date]
)
VAR Result =
CALCULATETABLE (
VALUES ( 'Table'[Date] ),
'Table'[Date] = LastDayInMonth
)
RETURN
Result

Measure not filtering lastdate

I can't get Power BI to filter by last date in file.
When I try:
test = CALCULATE(
DISTINCT(table[Date]),
filter(
all(table[Date]),
table[Date] = date(2019,3,1)
)
)
It returns me the date March 1, 2019.
But if I use
test = CALCULATE(
DISTINCT(tabela_ajustada[Data]),
filter(
all(tabela_ajustada[Data]),
tabela_ajustada[Data] = LASTDATE(tabela_ajustada[Data])
)
)
It won't work, it's not filtering at all, so I get an error because it returns multiple values and I can't add to the card.
table[Date] has multiple non unique values.
Change to:
test =
CALCULATE(
DISTINCT(tabela_ajustada[Data]),
FILTER(
ALL(tabela_ajustada[Data]),
tabela_ajustada[Data] = LASTDATE ( ALL ( tabela_ajustada[Data] ) )
)
)