I have data from a cab-request service, which I am trying to analyse how often a trip gets cancelled before a successful trip is made. In column 2, passengercancelled indicates cancelled trips and droppedoff indicates a successful trip. I am trying to create a formula that counts how many passengercancelled trips happen before a droppedoff trip for a given passenger passenger_id.
I have tried the below code but I get this error:
There's not enough memory to complete this operation. Please try again later when there may be more memory available.
previous_requests =
requests_with_cancel_all__[cancelled] +
MINX (
TOPN (
1,
FILTER (
requests_with_cancel_all__,
[trip_date] > EARLIER ( [trip_date] )
&& [passenger_id] = EARLIER ( [passenger_id] )
&& EARLIER ( [current_state] ) = "droppedoff"
),
[passenger_id], ASC,
[trip_date], ASC
),
requests_with_cancel_all__[cancelled]
)
Related
I am trying to do a burndown graph on PowerBI.
My data is a list of tasks. Each task has a numerical value (EFFORT) assigned to it and there is a total amount of effort for any given month (sum of all EFFORT). As tasks as set to DONE, the ongoing effort should be deducted from a running total and that value used to plot a graph. I have 3 columns
I would like to have measure to calculate EFFORT REMAINING for each date, i.e.
EFFORT REMAINING = TOTAL EFFORT - (EFFORT WHEN TASKS ARE DONE FOR EACH DAY)
For example,
I did get the consecutive dates displaying:
Burndown = CALENDAR(DATE(2022,7,1),DATE(2022,7,31))
and also the total effort (starting value)
TOTAL EFFORT = SUM(Issues[EFFORT])
Now for each date in table, I need to minus the accumulating total of EFFORT when the status is set to DONE
EFFORT REMAINING = Burndown[TOTAL EFFORT]-SUM(Issues[EFFORT]="DONE" ....
Im stuck after this last point. Can anyone help, please?
you are so close to the answer ). Convert SUM(Issues[EFFORT]="DONE" to:
CALCULATE(
SUM(Issues[EFFORT])
, SUM(Issues[Status]="DONE"
)
Have a nice day.
Please try this measure:
Please ensure that (1-Many) relationship is created between Burndown [Date] and Issues[ISSUE_CREATED] columns.
EFFORT REMAINING =
VAR TblSummary =
ADDCOLUMNS (
SUMMARIZE ( Issues, Burndown[Date] ),
"Total Effort", CALCULATE ( SUM ( Issues[EFFORT] ) ),
"Tasks Completed", CALCULATE ( SUM ( Issues[EFFORT] ), Issues[STATUS] = "DONE" ),
"Effort Remaining",
CALCULATE ( SUM ( Issues[EFFORT] ) )
- CALCULATE ( SUM ( Issues[EFFORT] ), Issues[STATUS] = "DONE" )
)
VAR Result =
SUMX ( TblSummary, [Effort Remaining] )
RETURN
Result
After that, you can create a clustered column chart, and put [Date field] on calendar table on X_axis and put 'EFFORT REMAINING' measure on Y_axis(Value axis) to see the result.
I hope It solves your problem.
Bonus Info:
If you want to see your Summary table, create a "New Table" and paste this code:
Summary_Table =
VAR TblSummary =
ADDCOLUMNS (
SUMMARIZE ( Issues, Burndown[Date] ),
"Total Effort", CALCULATE ( SUM ( Issues[EFFORT] ) ),
"Tasks Completed", CALCULATE ( SUM ( Issues[EFFORT] ), Issues[STATUS] = "DONE" ),
"Effort Remaining",
CALCULATE ( SUM ( Issues[EFFORT] ) )
- CALCULATE ( SUM ( Issues[EFFORT] ), Issues[STATUS] = "DONE" )
)
VAR Result =
SUMX ( TblSummary, [Effort Remaining] )
RETURN
TblSummary
The result It produces:
Note: I have limited access to your data sets as you shared above. The result will be exact with your full dataset.
I have a question regarding Dax formula in PowerBI. All help is appreciate. I need to present some results on monday...
Table example
Task column can have different fields (Partner Acknowledgment, IPM HandOff, Pre Engagement Process...)
Task status can only have 2 values (closed or Received)
I have my formulas that work but now I need to add an extra filter and is getting error:
THe Filter part is giving me problems (WHen task= IPM HandOff is Task_status = Closed)
Total Tasks = All the tasks (rows) that contains the word "Partner Acknowledgment" in the task column.....And I try to add a filter when "IPM HandOff" in the task column has task_status closed:
Tasks =
CALCULATE (
COUNTA ( CELERGO_12062021V1[TASK] ),
CONTAINSSTRING ( CELERGO_12062021V1[TASK], "Partner Acknowledgement" ),
FILTER (
CELERGO_12062021V1,
CELERGO_12062021V1[TASK] = "IPM HandOff"
&& CELERGO_12062021V1[TASK_STATUS] = "Closed"
)
)
Total Tasks with GLD = Same as the previous one but with a schedule Date in the column Schedule.....And I try to add a filter when "IPM HandOff" in the task column is Task_status = closed.
Partner Acknowledgment with GLD = CALCULATE ( COUNTA ( CELERGO_12062021V1[SCHEDULED] ), CONTAINSSTRING ( CELERGO_12062021V1[TASK], "Partner Acknowledgement" )) ,
FILTER (
CELERGO_12062021V1,
CELERGO_12062021V1[TASK] = "IPM HandOff"
&& CELERGO_12062021V1[TASK_STATUS] = "Closed"
)
)
Total Tasks with GLD = Same as the previous ones but with a schedule Date in the column Schedule and Task Status Closed for the task "Partner Acknowledgmeent".....And I try to add a filter when "IPM HandOff" in the task column is Task_status = closed.
Partner Acknowledgment with GLD & Closed = CALCULATE ( COUNTA ( CELERGO_12062021V1[SCHEDULED] ), CONTAINSSTRING ( CELERGO_12062021V1[TASK], "Partner Acknowledgement" ) && CELERGO_12062021V1[TASK_STATUS] = "Closed" ) ,
FILTER (
CELERGO_12062021V1,
CELERGO_12062021V1[TASK] = "IPM HandOff"
&& CELERGO_12062021V1[TASK_STATUS] = "Closed"
)
)
ANy idea got to add this extra field in the formulas? "WHen task= IPM HandOff is Task_status = Closed) Thanks :)
last part... Is it possible to get the formulas + extra filter counting only the tasks owned by some people (names??) I want to know the formulas below that belong to Taskactualperformer = Roger, Abbie and Veronika"?
Same table. I need to combined the 2 formulas below...
To get all the clients with
Task = "pre engagement Team" and Tast_Status (Closed and Received) - Formula 1
&&
Task = "IPM HandOff" and Task_Status is Received - Formula 2
Tried different options but no exit.
Formula1 = VAR result =
CALCULATE (
DISTINCTCOUNT( CELERGO_12062021V1[CID] ),
FILTER (
CELERGO_12062021V1,
CELERGO_12062021V1[TASK]
= "Pre Engagement Process"
&& CELERGO_12062021V1[TASK_STATUS] IN { "Closed", “Received” }
)
)
RETURN
IF ( ISBLANK ( result ), 0, result )
FOrmula 2 =
VAR result =
CALCULATE (
COUNT ( CELERGO_12062021V1[CLIENT_NAME] ),
FILTER (
CELERGO_12062021V1,
CELERGO_12062021V1[TASK] = "IPM HandOff"
&& CELERGO_12062021V1[TASK_STATUS] = "Received"
)
)
RETURN
IF ( ISBLANK ( result ), 0, result )
last part... Is it possible to get the formulas + extra filter counting only the tasks owned by some people (names??) I want to know the formulas below that belong to Taskactualperformer = Roger, Abbie and Veronika"?
Thanks
I would recommend splitting those measures into simple ones.
As I understand, you want to count the number of rows that contain 'Partner Acknowledgment' in the task column and add the number of rows that have the value "closed" in the status column and the value 'IPM HandOff' in the task column. Then you can try this:
Count rows:
Total Tasks =
COUNTROWS ( 'TableA' )
Count rows where tasks contain 'Partner Acknowledgment':
Partner_Acknowledgment_Total =
CALCULATE (
[Total Tasks],
CONTAINSSTRING ( 'TableA'[task], "Partner Acknowledgment" )
)
Count rows where tasks are equal to 'IPM HandOff' and status = 'closed'
IPM_HandOff_closed_Total =
CALCULATE (
[Total Tasks],
'TableA'[task] = "IPM HandOff",
'TableA'[status] = "closed"
)
Final measure:
Partner_Acknowledgment+IPM_HandOff_closed =
[Partner_Acknowledgment_Total] + [IPM_HandOff_closed_Total]
Measures are for the table:
I am trying to calculate whether a customer that uses a gift card as his first order, will transition into become a "normal" customer, which means that he/she orders without a gift card next time.
I can see from the PaymentMethod how the customer payed (PaymentMethod = "Gift card")
I have made a column that says "Gift card" if the order is purchased with this, otherwise it is blank.
So basically I want to make a column that states: If the customer has their first purchase with a gift card, and makes a new order later, that is not purchased with a gift card.
So for example a 1 if TRUE, a 0 if FALSE.
I have the following columns in my orders table:
OrderID
CustomerID
BookingDate
PaymentMethod (Cash, Credit Card, Gift card etc.)
Gift card (Blank or Gift card)
I have tried different DAX codes, but the thing is - I don't know how I would write that the first order has to be a gift card order, and the next order from the customer has to be a non-gift card order, so I doubt the DAX code that I have tried, would be relevant.
Here is a picture of what I hope to achieve:
I hope someone can lead me in the right direction, thank you in advance.
I'd suggest something along these lines:
TransitioningCustomer =
VAR FirstOrderDate =
CALCULATE ( MIN ( Data[BookingDate] ), ALLEXCEPT ( Data, Data[CustomerID] ) )
VAR FirstOrderGiftCard =
"GC"
IN CALCULATE (
VALUES ( Data[PaymentMethod] ),
ALLEXCEPT ( Data, Data[CustomerID] ),
Data[BookingDate] = FirstOrderDate
)
VAR PaymentMethods =
CALCULATE (
DISTINCTCOUNT ( Data[PaymentMethod] ),
ALLEXCEPT ( Data, Data[CustomerID] )
)
RETURN
IF ( FirstOrderGiftCard && PaymentMethods > 1, 1, BLANK () )
This calculates the first order date and then check whether a gift card was used on that date. It also counts the total number of (distinct) payment methods used.
The conclusion that if a gift card was used on the first date and there was some other type of payment method used as well as some point in the customer's purchase history, then that is a transitioning customer.
With the help of Alexis i ended up with this, that returns a 1 if a customer uses a giftcard for their first order, and something else than giftcard for their second order.
FirstOrderGiftNextOrderNotGift =
VAR FirstOrderID =
CALCULATE (
MIN ( orders[Column1.Order_ID] ),
ALLEXCEPT ( orders, orders[Column1.Customer_ID] )
)
VAR FirstOrderGiftCard =
CALCULATE (
VALUES ( orders[Column1.PaymentMethod] ),
ALLEXCEPT ( orders, orders[Column1.Customer_ID] ),
orders[Column1.Order_ID] = FirstOrderID,
orders[Column1.PaymentMethod] = "Giftcard"
)
VAR PaymentMethods =
CALCULATE (
DISTINCTCOUNT ( orders[Column1.PaymentMethod] ),
ALLEXCEPT ( orders, orders[Column1.Customer_ID] )
)
RETURN
IF (
FirstOrderGiftCard = "Giftcard"
&& orders[ReturningCustomer] = "Yes"
&& PaymentMethods > 1,
1,
0
)
After calculating this column I just created a measure for counting the distinct 1's of the customer numbers.
CountOfCustomersWhoTransitioned =
CALCULATE (
DISTINCTCOUNT ( orders[Column1.Customer_ID] ),
orders[FirstOrderGiftNextOrderNotGift] = 1
)
I want to show this year store count based on to date and from date.The following code is throwing this error when i am placing this column in table.
ThisYearStoreCount =
IF (
[DateDiff] > 365,
0,
IF (
DATESBETWEEN ( WUSA_CAL_DIM[End_Date], [From_Date], [To_Date] ),
DISTINCTCOUNTNOBLANK ( WUSA_STORE_DIM[Store Code] )
)
)
#RADO is spot on,
If I understand your logic, something like this should work.
ThisYearStoreCount =
IF (
[DateDiff] > 365,
0,
IF (
[From_Date] >= WUSA_CAL_DIM[End_Date]
&& [To_Date] <= WUSA_CAL_DIM[End_Date]
&& WUSA_STORE_DIM[Store Code] <> BLANK(),
1
)
)
That error usually means that you're using a function that returns a set of data, in a column context ( column contexts only allow a single value to exist per row ).
I'm reading between the lines a little bit, but the new column formula above will check if the end date is between the From_Date and To_Date before allowing the number 1 through.
Then you can just add the ThisYearStoreCount to any visual and it will sum wherever appropriate.
Your existing code should work as a measure ( instead of a column ) I think but it's impossible to tell without more information.
I'm trying to create a trending table with a value and a forecast. The forecast needs to start from the current month going forward. I am using this dax function:
Spend Forecast =
IF (
OR (
DIVIDE (
CALCULATE (
SUM ( refv_Spend_Cap[Spend_2019] ),
FILTER ( refv_Spend_Cap, refv_Spend_Cap[Split] = "Spend Actual" )
),
1000000
)
< 1,
DIVIDE (
CALCULATE (
SUM ( refv_Spend_Cap[Spend_2019] ),
FILTER ( refv_Spend_Cap, refv_Spend_Cap[Ind_Monthend] = "x" )
),
1000000
)
< 1
),
DIVIDE (
CALCULATE (
SUM ( refv_Spend_Cap[Spend_2019] ),
FILTER ( refv_Spend_Cap, refv_Spend_Cap[Split] = "Spend Forecast" )
),
1000000
),
""
)
The formula is calculating to check if these two conditions are met:
if there's no value then populate the forecast or if the ind monthend = 'x' then it should populate, if those two conditions are not met then it should leave it blank.
There are no syntax errors on the query but i am getting this error:
The True/False expression does not specify a column. Each True/False
expressions used as a table filter expression must refer to exactly
one column
Where did I go wrong?
It's very hard to comprehend such long formulas. It's the best practice to break them down into multiple measures. For example, your code can be re-writen as follows:
Create base measure:
Total Spend = SUM ( refv_Spend_Cap[Spend_2019] ) / 1000000
Now re-use the base measure to create 3 conditional measures. No need to use FILTER here:
Spend Actual = CALCULATE ( [Total Spend], refv_Spend_Cap[Split] = "Spend Actual" )
Spend X = CALCULATE ( [Total Spend], refv_Spend_Cap[Ind_Monthend] = "x" )
Spend Forecast = CALCULATE ( [Total Spend], refv_Spend_Cap[Split] = "Spend Forecast" )
Then the final result is simply:
Forecast = IF ( [Spend Actual] < 1 || [Spend X] < 1, [Spend Forecast], "")
It's much easire to understand what's happening, and easier to debug. You will also gain perfomance bonus because (usually) re-used measures are cached and calculated only once.
Try this code, if it still gives you problems, describe the new error and I'll help you fix it.
BTW, there is a popular free tool to format your DAX code:
Dax Formatter