Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I am new to power bi . My question is that is it possible to count sale in last three month and last year in the same table view.
Or how many sales has been done in last month and in last last week in the same table . How to display that in one table .
Section | Count This week | Count This Month | Count This Year |
Toy | 500 | 15000 | 50000 |
Solved! Go to Solution.
Hi @shahaabz,
You can refer to below measures:
Count of Last Week = var currProduct= LASTNONBLANK(Sheet1[Product Name],Sheet1[Product Name]) return COUNTAX(FILTER(ALL(Sheet1),Sheet1[Product Name]=currProduct&&WEEKNUM(Sheet1[Date])=WEEKNUM(TODAY())-1),Sheet1[Product Name])
Count of Last Month = var currProduct= LASTNONBLANK(Sheet1[Product Name],Sheet1[Product Name]) return COUNTAX(FILTER(ALL(Sheet1),Sheet1[Product Name]=currProduct&&and(MONTH(Sheet1[Date])=MONTH(EOMONTH(TODAY(),-1)),YEAR(Sheet1[Date])=YEAR(EOMONTH(TODAY(),-1)))),Sheet1[Product Name])
Count of Last Year = var currProduct= LASTNONBLANK(Sheet1[Product Name],Sheet1[Product Name]) return COUNTAX(FILTER(ALL(Sheet1),Sheet1[Product Name]=currProduct&&YEAR(Sheet1[Date])=YEAR(TODAY())-1),Sheet1[Product Name])
Sample:
Data table.
Create a visual to display these result:
In addition, if you want to get the sum of amount, you can use sumx function:
Sum of Last Year = var currProduct= LASTNONBLANK(Sheet1[Product Name],Sheet1[Product Name]) return SUMX(FILTER(ALL(Sheet1),Sheet1[Product Name]=currProduct&&YEAR(Sheet1[Date])=YEAR(TODAY())-1),Sheet1[Amount])
Regards,
Xiaoxin Sheng
Hi @shahaabz,
You can refer to below measures:
Count of Last Week = var currProduct= LASTNONBLANK(Sheet1[Product Name],Sheet1[Product Name]) return COUNTAX(FILTER(ALL(Sheet1),Sheet1[Product Name]=currProduct&&WEEKNUM(Sheet1[Date])=WEEKNUM(TODAY())-1),Sheet1[Product Name])
Count of Last Month = var currProduct= LASTNONBLANK(Sheet1[Product Name],Sheet1[Product Name]) return COUNTAX(FILTER(ALL(Sheet1),Sheet1[Product Name]=currProduct&&and(MONTH(Sheet1[Date])=MONTH(EOMONTH(TODAY(),-1)),YEAR(Sheet1[Date])=YEAR(EOMONTH(TODAY(),-1)))),Sheet1[Product Name])
Count of Last Year = var currProduct= LASTNONBLANK(Sheet1[Product Name],Sheet1[Product Name]) return COUNTAX(FILTER(ALL(Sheet1),Sheet1[Product Name]=currProduct&&YEAR(Sheet1[Date])=YEAR(TODAY())-1),Sheet1[Product Name])
Sample:
Data table.
Create a visual to display these result:
In addition, if you want to get the sum of amount, you can use sumx function:
Sum of Last Year = var currProduct= LASTNONBLANK(Sheet1[Product Name],Sheet1[Product Name]) return SUMX(FILTER(ALL(Sheet1),Sheet1[Product Name]=currProduct&&YEAR(Sheet1[Date])=YEAR(TODAY())-1),Sheet1[Amount])
Regards,
Xiaoxin Sheng
@shahaabz You can create three seperate measures under Modelling tab to achieve that for the same table.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.