Im working on a dashboard in PBI and I have the next problem...
I have a card that only have to show the month data. For this I use this measure:
Month Orders = CALCULATE(
DISTINCTCOUNT( 'Data'[ORDER] ),FILTER('Data',
'Data'[Month] = 'Data'[Actual Month]),
ALL('Data Incidentes')
)
I understand that if I use All() filter on a measure, this measure don't change when I apply a visual filter but in my case this change.
So my problem is that I have the card that show the month orders but when i apply a visual filter this data change and I don't want it to change.
I hope you understand my problem and my english jaja.
Month Orders = CALCULATE(
DISTINCTCOUNT( 'Data'[ORDER] ),FILTER('Data',
'Data'[Month] = 'Data'[Actual Month]),
ALL('Data Incidentes')
)
Can you try this instead-
Month Orders =
CALCULATE(
DISTINCTCOUNT( 'Data'[ORDER] ),
FILTER(
ALL('Data'),
'Data'[Month] = 'Data'[Actual Month]
)
)
Related
I tried to make a ranking on a date so that every beginning of a month it resets but I can't get it. the furthest I got is that every month simply gets an cumulative ranking based on RANKX on power bi which includes a month and a year.
Has anyone needed such a ranking and succeeded?
A generalised set-up for a Calculated Column would be along the lines of:
=
VAR ThisMonth =
MONTH( Table1[Date] )
RETURN
RANKX(
FILTER( Table1, MONTH( Table1[Date] ) = ThisMonth ),
Table1[Date],
,
ASC
)
I have a measure that depending on a "before" date slicer shows how many accounts were active at any given point in the company's history. I'm being asked to show month over month growth (end of month 1 compared to end of month 2 totals) but that's difficult given my measure needs a date slicer with one date value to return a total.
Active_Accounts =
CALCULATE (
COUNTX (
FILTER (
VALUES ( 'TEST CHARGES'[BI_ACCT] ),
[total as of date] > 0
),
[BI_ACCT]
)
)
link to sample file
https://www.dropbox.com/s/pewpm85wogvq3xf/test%20active%20charges.pbix?dl=0
if you move the slider you'll see the active accounts total change to show at that time in history how many accounts had an active charge. What I'm hoping to add to the dashboard is a measure that can be placed on a table of month end values and show the active accounts at that time so I can do month to month comparisons.
Active Accounts =
var month_end =
ENDOFMONTH (
LASTNONBLANK (
'Test Charges Date Table'[Date],
CALCULATE ( DISTINCTCOUNT( ( 'TEST CHARGES'[BI_ACCT] ) )
)
)
)
var last_date =
CALCULATE(
LASTNONBLANK('TEST CHARGES'[CHG_DATE], ""),
'TEST CHARGES'[CHG_DATE] <= max('Test Charges Date Table'[Date])
)
var num_of_actives =
CALCULATE(
Countx(
Filter(
Values('TEST CHARGES'[BI_ACCT]),
[total as of date] > 0
) , [BI_ACCT]
),
last_date <= month_end
)
return num_of_actives
As Peter advices you do not need Calculate() to show total in the card and using of Calculate() reduces speed of calculation. In your case speed is reduced with no reason.
There are no need to have a special column for month - use date hierarchy for row and just exclude day and quater levels.
Then add the measure to the visual table/matrix
Cummulative Count =
Calculate(
[Active_Accounts]
,'Test Charges Date Table'[Date]<=MAX('Test Charges Date Table'[Date])
)
Cummulative Count prevMonth =
Calculate(
[Cummulative Count]
,PARALLELPERIOD('Test Charges Date Table'[Date],-1,MONTH)
)
I have a problem of getting the percentage on customer sales in matrix table thta is sliced by store_id and employee_id using ALLEXCEPT function. The percentage of customer sales need to obrain from dividing customer sales measure in current filter by the same measure of the respective store_id, instead of total customer sales of all the store_id.
Here is my expectation of the output and the DAX when using ALL function on the staff_id.
% of Customer Sales =
VAR ALLExceptSales =
CALCULATE(
[Customer Sales],
ALL(
'Employee Lookup'[staff_id]
)
)
VAR Ratio =
DIVIDE(
[Customer Sales],
ALLExceptSales,
BLANK()
)
RETURN Ratio
I have tried using ALLEXCEPT on store_id from sales by store table, ALLEXCEPT store_id from store lookup table and ALLEXCEPT on both the tables, still giving me different output.
Here is the pbix file for testing.
https://drive.google.com/file/d/1fRrfsikHl9aK06GzAozJ9Wc16Ue0YJm2/view?usp=sharing
Anyone can hint me on?
Replace DAX with following
% of Customer Sales =
VAR ALLExceptSales =
CALCULATE(
sum(Table[Customer Sales]),
ALLEXCEPT(Table, 'Table'[store_id])
)
VAR Ratio =
DIVIDE(
sum(Table[Customer Sales]),
ALLExceptSales,
BLANK()
)
RETURN Ratio
Have you tried ALLSELECTED instead of ALLEXCEPT?
% of Customer Sales =
DIVIDE (
[Customer Sales],
CALCULATE ( [Customer Sales], ALLSELECTED ( 'Employee Lookup'[staff_id] ) )
)
I have salesman dimension and sales fact with 1:M relationship on salesman_id.
I am trying to create a measure for count of salesman that have made sales in location is 6.
CALCULATE (
DISTINCTCOUNT ( Salesman[SalesmanKey] ),
Sales,
Sales[LocationId] = 6
)
I think this is not working because the filter doesn't flow from sales into salesman table.
I could change the filter direction as both but I'm looking at other option like using DAX CALCULATE with CROSSFILTER. Is there any other option like using CALCULATETABLE?
You can use the following Dax formula to achieve your goal:
Measure =
CALCULATE(
DISTINCTCOUNT( Salesman[SalesmanKey] ),
CROSSFILTER( Sales[salesman_id], Salesman[SalesmanKey], Both ),
Sales[LocationId] = 6
)
However I recomend you using the salesman id from the fact table:
Measure =
CALCULATE(
DISTINCTCOUNT( Sales[salesman_id] ),
Sales[LocationId] = 6
)
Edit: i added the option using the calculatetable:
Measure =
CALCULATE(
DISTINCTCOUNT( Salesman[SalesmnaKey] ),
CALCULATETABLE(
Sales,
Sales[LotacionId] = 6
)
)
In order to track our average headcounts and turnover trends, I had created a report in Power BI that essentially expanded a table with employee start/end information to give a record for each associate every day they were employed at the company.
While this solution works, I end up with a table containing millions of rows which does not seem very efficient.
I have looked into other possible solutions in DAX, but have not found anything that will give me the exact same output. It seems like most solutions rely on taking the timing from the start date and end date of a month and then averaging them, which is not quite what I am trying to do.
I have attached a simplified pbix file that shows the desired output of what I am trying to get at. Any advice would be appreciated.
pbix example
Final code ended up looking like this:
All Employees = countrows ('Employees')
Terminations =
Calculate(
Countrows('Employees'),
USERELATIONSHIP('Employees'[End Date],'Calendar'[Date])
)
Active Employees =
AVERAGEX(
VALUES('Calendar'[Date]),
VAR CurrentDate = 'Calendar'[Date]
VAR HiredBeforeCurrentDate =
Filter(
ALL('Employees'[Start Date]),
'Employees'[Start Date] <= CurrentDate
)
VAR HiredAfterCurrentDate =
FILTER(
ALL('Employees'[End Date]),
OR('Employees'[End Date] >= CurrentDate, isblank('Employees'[End Date])
)
)
RETURN
CALCULATE(
Countrows('Employees'),
HiredBeforeCurrentDate,
HiredAfterCurrentDate,
ALL('Calendar')
))