I am new to Power BI and learning how to perform cohort analysis with DAX in Power BI. Is there any way to find out how many times (or if easier if a customer buys more than a certain threshold) their first month?
If I have the table Customers:
ID | DateOfFirstRegistration
And the table of orders:
ID | customerId | orderDate
Let me know if any more information is helpful!
EDIT: If possible, is it also possible to plot it in a matrix with customers in each row and month 1 through 3 in the columns?
Thank you
You can do something like this measure in a table visualization together with customer ID:
First Month Purchases =
VAR _registration =
SELECTEDVALUE ( 'customers'[DateOfFirstRegistration] )
RETURN
CALCULATE (
COUNTROWS ( 'orders' ) ,
DATESINPERIOD (
'orders'[orderDate] ,
_registration ,
1 ,
MONTH
)
)
Related
I have a dataset and I want to create a column(not measure) to calculate the count of customers in each month. I don't know how I can count each customer once a month in Power BI.
I wrote this code but it counts the number of frequent customers more than once a month.
myCol = CALCULATE( DISTINCTCOUNT('table'[user_id] ) , 'table'[order_date] )
For example, it's my data:
The true result should be:
but my code returns this result:
How should I write the code for this calculating column to get a true result?
Since you are trying to calculate per month, you need a "year_month" column.
Then:
count_of_customer =
CALCULATE(
DISTINCTCOUNT('table'[user_id]),
ALLEXCEPT('table', 'table'[year_month])
)
Result:
Edit:
You don't need a calculated column, you need a measure:
count_of_customer =
COUNTROWS (
SUMMARIZE ( 'table', 'table'[year_month], 'table'[user_id])
)
So, I have the following tables in my Power BI :
Sales : Date | ID_Client | ID_Product | Amount
Client : ID_Client | Name_Client
I would like to get the number of unique BIG clients in any given month. I therefore use the following formula (which I then put in a column in a table with months in rows):
# BIG Clients =
VAR threshold = 10000
RETURN
(
CALCULATE(
DISTINCTCOUNT( Sales[ID_Client] ),
FILTER(
SUMMARIZE(
Sales,
Sales[ID_Client],
"Sales", SUM( Sales[Amount] )
),
[Sales] >= threshold
)
)
)
QUESTION IS : how can I get the list of those BIG clients for any given month? Let's say I click on the November number of big clients in my table, could another table nearby display the list of those clients ?
Thanks in advance for your kind help, I've been trying for a while :)
I assume that you have a table of clients with the Name column with a one to many relationship with the Sales table and that you do not have duplicate client names. Then you may create a [BIG Sales] measure to be used in a table or matrix visual with client names on the rows.
since [BIG Sales] evaluates to BLANK() for clients with less that threshold sales, they are automatically filtered out from the visual
BIG Sales =
VAR threshold = 10000
VAR BigCustomers =
FILTER(
ADDCOLUMNS(
VALUES( Clients[Name] ),
"Sales", SUM( Sales[Amount] )
),
[Sales] >= threshold
)
RETURN
SUMX(
BigCustomers,
[Sales]
)
You could create a table or matrix visual with the client on the rows and use your measure in the values field. This will show 1 for all big clients and return blank for the rest (which should hide them). If you don't want to show the measure, you can set the value is 1 in the filter pane and remove the measure from the values field.
A more direct option is to use a simple SalesAmount = SUM ( Sales[Amount] ) measure in the values field and filter like this
I am working in Power BI and I created a DAX measure that adds up two other DAX measures.
For one measure I need it to ignore the month slicer because I need the total for that category. Is it possible to do so?
Also, is it possible for it to ignore the slicer and still give me the total for unfiltered DAX measure + the date filter DAX measure?
DAX code:
Monthly Total Act =
CALCULATE (
SUM ( 'sheet1'[Amount] ),
FILTER ( 'sheet1', 'sheet1'[Type] = "ACT" ),
FILTER ( 'sheet1', 'sheet1'[Bill] = "Y" )`
)
Monthly Total of Acs =
CALCULATE (
SUM ( 'sheet1'[Amount] ),
FILTER ( 'sheet1', 'sheet1'[Type] = "ACR" ),
FILTER ( 'sheet1', 'sheet1'[Bill] = "Y" )`
)
Adding these two formulas together to get the total monthly.
The monthly total of ACS is where I encounter the problem. I need this to be unaffected by the slicer
The end goal is having the month total of ACS unaffected by the data slicer and add to the monthly total of Act that requires filter by the current month.
Yes, you can add this line as a third filter argument in the calculat function you want to ignore the month slicer:
ALL('tableName'[monthColumnUsedAsSlicer])
Then the monthe slicer will not affect calculations.
I am having issues getting the month over month percentage in power bi. I have column that contains the yyyy-mm data in dim table and i have a percentage column in fact table. I dont see Time intelligence under Quick measure as well.
Percentage MoM% =
IF (
ISFILTERED ( 'output'[Period] ),
ERROR ( "Time intelligence quick measures can only be grouped or
filtered by the Power BI-provided date hierarchy or primary date column." ),
VAR __PREV_MONTH =
CALCULATE ( [Percentage], DATEADD ( 'output'[Period].[Date], -1, MONTH ) )
RETURN
DIVIDE ( [Percentage] - __PREV_MONTH, __PREV_MONTH )
)
Getting error that time intelligence needs date hierarchy but i dont have one. Is there any other way to achieve this?
Thanks
I have a table which contains a list of products scores by date:
From this table, I have to make a plot of the cumulative percentage of each quality by date.
At this moment I have the percentage of each class by day:
For that I used this measurement:
Measure =
CALCULATE (
SUM ( Table1[Percentage_By_Class] ),
FILTER ( Table1, Table1[Date] = MAX ( Table1[Date] ) ),
ALLEXCEPT ( Table1, Table1[Score] )
)
/ CALCULATE (
SUM ( Table1[Percentage_By_Class] ),
FILTER ( ALL ( Table1 ), Table1[Date] = MAX ( Table1[Date] ) )
)
But this only considers the percentage of each day. I need to consider all previous dates. E.G. for day 2 I need to consider days 1 and 2, for day 3 I need to consider days 1,2,3 and so on.
How can I accomplish this?
in my opinion, you need a calendar for the date first, you can create a table easily bay dax function =CALENDARAUTO() And mark it as a calendar table,
After that, you can use a DATEMTD or a DATEYTD function for your coding purpose.
here are the steps:
1 - https://learn.microsoft.com/en-us/dax/calendarauto-function-dax
select left pane --> table --> modelling / create table and add dax formula
2- reference the table as a date table, right click on the table from the right pane
after then you can use data functions like YTD MTD ,
new measure :
1st mesure : AVG1 = AVG(DATA_)
2nd measure : YTD AVG ALL = CALCULATE([AVG1];DATESYTD(CALENDAR[DATE]))
REF: https://learn.microsoft.com/en-us/dax/dateadd-function-dax
then you can use MONTH(CALENDAR(DATE)) on left and YTD AVG as a value at any table...
regards.
SUNAY