Power BI cumulative count with DAX - powerbi

Here is a table of two rows:
ItemID
Date1
Date2
Category
1
2019-03-18
2020-07-31
A
1
2020-10-18
2020-07-31
A
Cumulatively count the number of unique items by category where Date1 >= Date2
I created a measure (thanks #jprzd) for a column chart:
Measure = CALCULATE(DISTINCTCOUNT(Table[ItemID]),FILTER(ALLSELECTED(Table),Table[Date1]>=Table[Date2]))
It does not result in the correct cumulative count. I think the above DAX expression is likely in the right direction, but I couldn't figure out where it went wrong.
I'd greatly appreciate your help.

Related

Get Daily sum in PowerBI

I have a table with date and sales but when I applied summation to get daily sum it gives wrong results. I used:
Daily Sales = SUM(sales[Sales])
My original table:
Date
Sales
1/1/2018
454670
1/1/2018
458791
1/2/2018
454670
1/2/2018
458791
After using the formula, I get summation as below (which is wrong):
Date
Daily Sales
1/1/2018
99597528
1/2/2018
111423077
Please help!

Measure (CALCULATE) - two fact tables

Hi DAX Experts around the world,
I hope you can help me with below problem. In short:
there are two fact tables: Table1 and Table2 , not connected between each other and cannot be appended.
they have both relation to Calendar table
I need to create a measure which will return some part from Table1 and a part form Table2, as described on the picture.
When a Nov-21 is selected on the slicer, measure should return Actuals for first 10 months of the year with 100 each month (from Table1) and remaining 2 months with Forecast values from with 200 each month (from Table2).
Is it possible at all as I am out of ideas ?
Thank you in advance.
Max
You can create a copy of the calendar table(Calender (2)), which can be used to create a slicer.
With the help of this table, you can create a measure to calculate the value based on selected date like this:
Amount Measure =
VAR _selected_date = MAX('Calender (2)'[Date])
return SUMX(SUMMARIZE(Calender,Calender[Date]),IF('Calender'[Date]<_selected_date,SUMX(FILTER(Table1,Table1[Version]="Actual"),[Amount]),SUM(Table2[Amount])))

DAX: How to count how many months have sales in a period

In my fact table (fTable) the columns I have are dates, region and sales.
dates
region
sales
-----
------
-----
I am visualizing the data in a pivot table with regions as rows and months as columns (I have a date table (dDate) with a months column in my model)
I am looking for a way to dynamically change the denominator in an averaging measure if a certain region doesn't have sales in a given month. Right now my denominator is hard-coded as 6, because I am averaging 6 variables in my nominator, but any one of them could be 0 if I don't have any sales in a certain month, in which case my denominator needs to change to 5, 4 or less depending on how many months I don't have sales in. So I am looking to count how many of the past 6 months have sales and sum that as the denominator.
I have managed to count months with sales this way:
Denominator:=
var newTable = Summarize(fTable,fTable[date (month)], fTable[region],"Sales",[Sum of Sales])
var MonthsWithSales = Countrows(newTable)
RETURN
MonthsWithSales
I've tried to RETURN
Calculate(SUMX(newTable,MonthsWithSales), Dateadd(dDate[Date],-6,MONTH)
but it yields a wrong result.
Any suggestions?
Thanks
Based on my sample, we can use function VALUES & COUNTROWS inside CALCULATE to get what we need:
Measure = CALCULATE( COUNTROWS(VALUES('Table (2)'[Month])), ALL('Table (2)'[Month]) )

Power BI DAX data from 2 tables

I have 2 tables see image
And I want to get total revenue for Store ABC only for product "ID1" so in this simple tables the final Revenue should be 251.
So I should filter only "ABC" in first table and filter only "ID1" in the second and then add column "Revenue" to the first table with the key "email" and then SUM revenue, but I got completely lost how to write it in DAX
Any suggestions?
Thanks
Lukas

PowerBI Measure - Previous Quarter With Filter

I am trying to create a measure to calculate the sum of sales for the previous quarter with a filter.
This is what I tried:
PQ Retail Sales = CALCULATE(SUM(MASTER_SALES_REPORTING_COMPETITION[Retail Sales $]),
FILTER(MASTER_SALES_REPORTING_COMPETITION,
MASTER_SALES_REPORTING_COMPETITION[Vendor Grouped] = "Company A"),
PREVIOUSQUARTER(DateDim[Date]))
Is there a logical error with the dax? PowerBI doesn't pick up any errors however I get a blank result.
Thank you.