I am trying to produce a cluster column chart with Month/Year as the x-axis and the number of enrolled and finished students within each month as y-axis, which would look like this (navy: enrolled students, red: finished students; A: April, B: May, etc):
In EXCEL, what I want to do would be simply put as:
Number of Enrolled = COUNTIFS('Student Enrolment Date', '>=01/04/2021', 'Student Enrolment Date', '<=01/04/2021')
Number of Completed = COUNTIFS('Student Finish Date', '>=01/04/2021', 'Student Finish Date', '<=01/04/2021')
Then use the calculated values to produce a visual.
The data example (let's call it Student) is as below:
I have also produced a date dimension as below:
I get confused about how to do this using DAX. If I connect Student['course start date'] with Date['Date'], and use Date['Year-Month'] as x-axis as below, then Power BI will count all students whose Student['course start date'] fall into each month. But because students is not necessarily get enrolled and finished in the same month, this method is apparently incorrect.
My questions are:
I am now trying to count the date in Student['student enrolment date'] and Student['student finish date'] within each month using:
Student Complete = COUNTROWS(FILTER(Student, Student[Status]="Complete" && Student[student enrolment date]>=DATE(2021, 4, 1) && Student[student enrolment date]<=DATE(2021, 4, 30) + 0))
but DAX says this is not a correct formula, and I don't know how to make this formula calculate for each month. Could you please correct me?
In my case, how to properly connect the date dimension to the Student dimension?
I think your model is not ok and that's why your DAX is much more complicated than necessary.
Create a fact table that connects your dimensions.
e.g. factStudentEvents
StudentId dateId Enrollments Completions
----------- ----------- ----------- -----------
1 20210413 1 0
1 20210620 0 1
2 20210427 1 0
Like this your DAX measures are very simple:
Completion Count = SUM(factStudentEvents[Completions])
Enrollment Count = SUM(factStudentEvents[Enrollments])
Related
I hope you are all doing well,
I am stuck at a problem and can't find a ways out. I have a sample table with shops name, target and date. Based on the target a dax measure is written which which will define the category for that particular shop.
for example if I select date between 1 december, 20222 to 2 decemeber 2022 than the category of a1 store will be "D" however if choose date upto 3 december , 2022 the category of a1 store will be "A". Following dax is used to assign the category.
Category =
var t1 = sum('Table'[Target])
return
if(t1 >=15 ,"A", if(t1<15 && t1>=10, "B", if(t1>10 && t1<=5, "C","D")))
Now I want to count the total number of stores fall in a specefic category based show the total against those stores with respect to the chosen date and show blank in total for category and for count.
The output should be like this.
Kindly help
To create dax measure based on my requirements mentioned before.
I am working to get cumulative distinct count of uids on daily basis. My dataset consists dates and UserIDs active on that date. Example : Say there are 2 uids (235,2354) appeared on date 2022-01-01 and they also appeared on next day with new uid 125 (235,2354,125) on 2022-01-02 At this point i want store cumulative count to be 3 not 5 as (user id 235 and 2354 already appeared on past day ).
My Sample Data looks like as follows:
https://github.com/manish-tripathi/Datasets/blob/main/Sample%20Data.xlsx
enter image description here
and my output should look as follows:
enter image description here
Here's one way that seems to work, using your linked Excel sheet as the data source.
Create a new table:
Table 2 = DISTINCT('Table'[Date])
Add the columns:
MAU = CALCULATE(
DISTINCTCOUNT('Table'[User ID]),
'Table'[Date] <= EARLIER('Table 2'[Date]))
DAU = CALCULATE(DISTINCTCOUNT('Table'[User ID]),
'Table'[Date] = EARLIER('Table 2'[Date]))
Result from your Excel data
I have table in Power BI with following columns: Country, Date and event. I would like to add measure or new column if needed with 'Start Day'. 'Start Day' assignes value '1' at the first day that value greater than 0 apears in column 'event' and starts counting days from this date. In example below for country UK value 1 in column 'event' apears on 19/03/2020 and in column 'Start Day' value 1 is assigned. Next date 20/03/2020 has value 2 assigned and so on. What is the best way to do this in Power BI?
Robert
You need to create an extra column as this is static data.
You can do this by first getting the start date of that country and then take the datediff between the dates.
In the CALCULATE function, I get all rows where the country is equal and where the event = 0. From those rows, I get the max date (firstD). This was the most important step as we can now use the DATEDIFF to calculate the days.
I used the max function once more because you want to have 0 in the rows before the startdate.
Start Day =
var country = events[Country]
var firstD = CALCULATE(MAX(events[Date]);FILTER(events;events[Country] = country && events[event]=0))
return max(DATEDIFF(firstD;events[Date];DAY);0)
I couldn't find an answer for my issue elsewhere, so trying my luck here.
I have sales table and my final result should determine if there were sales made for same person in specific period of time, for example within 7 business days. for example:
For ID 123 I have to flag it that sale for products A,B,C where within specified period.
For ID 1234 only sales of products A and B meet the criteria product C was sold in irrelevant time frame.
I've created a date table with indicators that determine for each date if the date is a working day, but i am struggling to calculate the relevant last working day
For example: I need that for 01/01/2019 i will get 10/01/2019 date, based on NUMOFDAYS and FinalWorkday = TRUE, which basically means that i have to count NUMOFDAYS times TRUE statement for each date and return corresponding date.
After that step done I think that it would be pretty easy for me to determine if the sale for a person was made in specific time frame.
If someone can give me direction for that much appreciated
Thank you in advance
You could use a DateTable like this one:
I used the following DAX-expressions for the calculated columns:
nrDays = 7
isWorkDay = WEEKDAY('DateTable'[Date],2) < 6
rankWorkingDays = RANKX ( FILTER ( DateTable, DateTable[isWorkDay] = TRUE () ),
DateTable[Date] , , ASC )
LastWorkDay = LOOKUPVALUE ( DateTable[Date],
DateTable[isWorkDay], TRUE (),
DateTable[rankWorkingDays], DateTable[rankWorkingDays] + DateTable[nrDays])
This issue can be solved by the following, since three are non-working days/holidays we can filter them out via POWERQUERY, than add an Index Column and Another column Which is basically Index column + Number of days wanted, then simply merge duplicate of dates query on Index+number of days wanted column on Index column. And we get the correct date
I am working on getting the amount of new sales and lost sales with regards to sales previous year and sales year to date. I am trying to show this in a table and then filtering that table with a year slicer.
Below are the formulas that i have used:
SalesPY = CALCULATE(SUM(SalesData[Value]),SAMEPERIODLASTYEAR('Calendar'[DateKey]))
SalesYTD = TOTALYTD(SUM(SalesData[Value]), 'Calendar'[DateKey])
NewSalesUppdate = SUMX(VALUES(SalesData[CustomerName]),IF([SalesYTD] > 0 && [SalesPY] = 0, [SalesYTD]))
LostSalesUppdate = SUMX(VALUES(SalesData[CustomerName]),IF([SalesYTD] = 0 && [SalesPY] > 0, -[SalesPY]))
LostSalesOld = IF([SalesPY] > 0 && [SalesYTD] = 0, -[SalesPY])
The NewSalesUppdate formula works as it should and sums up correctly. However LostSalesUppdate does not work, despite having pretty much the opposite formula compared with NewSalesUppdate. It seems like the IF statement never becomes true. That is strange because the LostSalesOld formula shows the right value, but it does not show the total.
All tips are appreciated!
Sample Data:
Current Result:
Notice how customer A had no YTD sales. The LostSalesOld shows -85000 in sales, but nothing is reflected in the total. The LostSalesUppdate shows nothing at all.
Desired Result:
Now one of the lost sales columns (doesn't matter which) has a value for customer A, and a total
Focusing on LostSalesUppdate, the issue is one of context. Your measure is saying "For each customer name in the SalesData table, show me last year's sales negated if they had sales last year and none this year".
The problem (and I'll admit it is subtle), is that because there are no sales for Customer A this year, Customer A is not in the SalesData table as far as this measure is concerned. Therefore, the rest of the formula is ignored.
What I would recommend is adding a separate table with a list of customers, similar to your date table (one row per customer). Then, update your LostSalesUppdate formula so that instead of pulling CustomerName from SalesData, it pulls it from your new customer table.
LostSalesUppdate =
SUMX (
VALUES ( Customer[CustomerName] ),
IF ( [SalesYTD] = 0 && [SalesPY] > 0, - [SalesPY] )
)