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
)
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 done a Measure to get the Revenue from TOP N Products.
N depends on the selected Value from my TOP-N Table (It's containing just the numbers from 1 to 10).
In the same Measure, I also calculate how much was the revenue of all Products how were not in the selected Top N.
The Code for this is:
Top N Produktbez Sum DB3 =
VAR TopNSelected =
SELECTEDVALUE ( 'TOP N-Filter'[TOP N] )
VAR TopNProdbezTable =
TOPN ( TopNSelected, ALLSELECTED ( 'Pseudo Produkbez Table' ), [DB3] )
VAR TopNProdbez =
CALCULATE ( [DB3], KEEPFILTERS ( TopNProdbezTable ) )
VAR OtherSales =
CALCULATE ( [DB3], ALLSELECTED ( 'Pseudo Produkbez Table' ) )
- CALCULATE ( [DB3], TopNProdbezTable )
VAR CurrentProd =
SELECTEDVALUE ( 'Pseudo Produkbez Table'[Produktbezeichnung] )
RETURN
IF ( CurrentProd <> "Others", TopNProdbez, OtherSales )
Now I want to add Year as Filter.
I'm using the Year coming from the Date Hierarchy.
Unfortunately, I can't provide a sample yet.
If a sample is need, I will try to create own.
I am trying to further develop a formula which has condition as below :
Choose the desired ID, it will look at the Volume value of the Products of that ID and it will multiply that volume value into the x.Value of the same products with different IDs.
Now I want to choose the products, and if an specific ID does not have that particular product I want it to still return the "chosen ID's Product's "X Value" * chosen ID's Product's Volume value and show in my Stack column.
so for example from attached Data set I would like to choose an ID for example 4321, and it contained product that wasn't available in the other ID's , it will choose the X and volume value of 4321 and show us in the stacked columns? So For example, the product E does not exists in the ID 1234 and 5566 so when it is showing us the final numbers with the volume of 4321 in a, B , C it will also return the Product E into them?
here is the previous formula which needs to be further developed and the previous post which is related to this question :
Desired Volume Measure
SUMX (
Table2,
VAR LookupID =
IF (
HASONEVALUE ( 'ID List'[ID ] ),
VALUES ( 'ID List'[ID ] ),
BLANK()
)
VAR LookupProduct =
IF (
HASONEVALUE ( Table2[Product] ),
VALUES ( Table2[Product] ),
BLANK()
)
VAR EffectiveVolume =
CALCULATE (
SUM ( Table2[Volume] ),
ALL ( Table2 ),
Table2[ID ] = LookupID,
Table2[Product] = LookupProduct)
RETURN
(Table2[X.Value]) *
IF (
ISBLANK ( EffectiveVolume ),
Table2[Volume],
EffectiveVolume
)
)
Automated formula to select values from a specifid ID and multiply to the rest with the same Name
I tried adding a condition which I thought might be useful, but unfortunately it doesnt work by adding :
VAR EffectiveXValue =
CALCULATE (
SUM ( Table2[X.Value] ),
ALL ( Table2 ),
Table2[ID ] = LookupID,
Table2[Product] = LookupProduct)
RETURN
IF(ISBLANK(ISFILTERED(Table1[Product])),EffectiveXValue,Table2[X.Value])*
IF (
ISBLANK ( EffectiveVolume ),
Table2[Volume],
EffectiveVolume
)
)
Thanks a Million
I need to calculate the ongoing revenue for installation + maintenance for projects and calculate the monthly revenue for controlling purposes in DAX in Power BI.
The problem is the following.
The projects are stored in a table CONTRACTS like this:
And I have a separate date table INST_DATE_TABLE:
The tables are connected via the [INSTALLATION_DATE] field.
For every month the revenue is the total of the [INSTALLATION_REVENUE] if the installation was carried out that month plus from the first month on the monthly maintenance revenue which is given as the [MAINTENANCE_COST_PER_UNIT] * [MAINTENANCE_UNIT] / 12.
And the maintenance revenue should be only calculated if the current date is beyond the installation date!
Some contracts are not yet signed, so they dont't have an installation date set (NULL)
So the INSTALLATION REVENUE DAX is like this:
.INSTALLATION_REVENUE =
CALCULATE (
SUMX(CONTRACTS;
CONTRACTS[INSTALLATION_REVENUE]
);
CONTRACTS[INSTALLATION_DATE] > 0
)
And the MONTHLY REGULAR REVENUE is like this:
.REGULAR_REVENUE =
CALCULATE (
SUMX(CONTRACTS;
CONTRACTS[MAINTENANCE_COST_PER_UNIT]*CONTRACTS[MAINTENANCE_UNIT]
) / 12;
CONTRACTS[INSTALLATION_DATE] > 0
)
For all dates I can calculate the cash flow of the latter like this:
.REGULAR_REVENUE_ONGOING =
CALCULATE (
[.REGULAR_REVENUE];
ALL(INST_DATE_TABLE[INSTALLATION_DATE])
)
which gives me a nice series of monthly revenues for all periods. But I only would like to see this for the periods that are beyond the installation date!
So lets say filtered on contract 1 I have now the following cash flow:
But for periods before 2019.04.01 I would like to see zeros!
How can I do that?
I just can't filter on dates referring to the installation date of the project!
After I have the expected result for one contract it would be easy to sum it up for all contracts like this
.TOTAL_REVENUE =
[.INSTALLATION_REVENUE] + [.REGULAR_REVENUE_EXPECTED]
UPDATE:
I created a cumulative total to display the ongoing revenue as such:
.REGULAR_REVENUE_ONGOING =
CALCULATE (
[.REGULAR_REVENUE];
FILTER(
ALL(INST_DATE_TABLE[INSTALLATION_DATE]);
INST_DATE_TABLE[INSTALLATION_DATE
<=MAX(INST_DATE_TABLE[INSTALLATION_DATE])
)
)
this displays the correct series, but now I have another problem. When I try to cumulate this already cumulative data series it does not add up as a cumulative data series!
Any help would be appreciated
.REVENUE_TOTAL_CUMULATIVE =
CALCULATE(
[.REVENUE_TOTAL];
FILTER(
INST_DATE_TABLE;
INST_DATE_TABLE[INSTALLATION_DATE] <= MAX(INST_DATE_TABLE[INSTALLATION_DATE])
)
)
Assuming there are no end dates to your ongoing revenue, then try:
.REGULAR_REVENUE_ONGOING =
VAR DateMin =
CALCULATE(
MIN ( CONTRACTS[INSTALLATION_DATE] ),
ALL ( INST_DATE_TABLE )
)
VAR DateMax =
MAX ( INST_DATE_TABLE[INSTALLATION_DATE] )
RETURN
SUMX (
FILTER (
ALL ( INST_DATE_TABLE ),
INST_DATE_TABLE[INSTALLATION_DATE] >= DateMin && INST_DATE_TABLE[INSTALLATION_DATE] <= DateMax
),
[.REGULAR_REVENUE]
)
And for a cumulative total revenue:
.REVENUE_TOTAL_CUMULATIVE =
VAR DateCurrent = MAX ( INST_DATE_TABLE[INSTALLATION_DATE] )
VAR CumulativeInstallationRevenue =
CALCULATE (
[.INSTALLATION_REVENUE],
FILTER (
ALL ( INST_DATE_TABLE ),
INST_DATE_TABLE[INSTALLATION_DATE] <= DateCurrent
)
)
VAR CumulativeOngoingRevenue =
SUMX (
FILTER (
ALL ( INST_DATE_TABLE ),
INST_DATE_TABLE[INSTALLATION_DATE] <= DateCurrent
),
[.REGULAR_REVENUE_ONGOING]
)
RETURN
CumulativeInstallationRevenue + CumulativeOngoingRevenue
See https://pwrbi.com/so_55808659/ for worked example PBIX file
I created 80/20 segmentation in my Power BI data model and I got what I wanted (see the table below).
Now I want to calculate new Name column with the next logic: if Cumulative % <=80% show value from the "Customer Name" column, otherwise show "Other" (the result will be the column Name as in the table below).
I tried with this calculated column but it doesn't work (the result isn't correct, it's always "Other"):
80/20 Name = IF([Cumulative Percen.] <= 0.8, SalesReport[Names], "Other")
Note: "Cumulative Percen." is calculated measure.
How can I do this?
In the next step, I'll use a pie chart to show this segmentation where all customers with small cumulative transactions will be categorized as Other.
The calculated measures that I used:
Customer Rank by Transaction =
IF (
HASONEVALUE ( SalesReport[CustName] ),
RANKX (
ALLSELECTED ( SalesReport[CustName] ),
CALCULATE ( [# of Transactions] ),
,
DESC,
DENSE
)
)
Customer Cumulative Transaction =
VAR CurrentCustimerRank = [Customer Rank by Transaction]
RETURN
SUMX (
FILTER (
ALLSELECTED ( SalesReport[CustName] ),
CALCULATE ( [Customer Rank by Transaction] ) <= CurrentCustimerRank
),
CALCULATE ( DISTINCTCOUNT ( SalesReport[CustID] ) )
)
Customer Cumulative Transaction Percen. =
[Customer Cumulative Transaction]
/ CALCULATE (
DISTINCTCOUNT ( SalesReport[CustID] ),
ALLSELECTED ( SalesReport[CustName] )
)