Forum Discussion
gbarr12345
Post Prodigy
2 years agoMacBook Sold in April measure
Hi everyone,
I'm looking to create a measure to put onto a card visualisation based on the number of Mac Books Sold in April.
I created the measure and got no error but when I pull it into a card the number that appears is incorrect.
Any idea why this number is a lot higher than it should be?
I have the code below and PBIX attached.
MacBook Sold April =
VAR _Item = SELECTEDVALUE( 'Sales Table'[Item Code])
VAR _Period = SELECTEDVALUE( 'Sales Table'[Period])
VAR Sales_Period =
VALUES( 'Sales Table'[Period] )
VAR VirtualTable =
FILTER(
SUMMARIZE(
'Sales Table' ,
'Sales Table'[Period] ,
'Sales Table'[Item Code] ,
'Dimension_Item Table'[Item Description]
),
'Sales Table'[Item Code] = 7
|| 'Sales Table'[Period] = 202404
)
RETURN
COUNTROWS(VirtualTable)
PBIX - https://drive.google.com/file/d/1pRRLgjcz7Ooo-yXndknfLtYqryr0lOR3/view?usp=drive_link
gbarr12345 you could try this formula:
CALCULATE(COUNTROWS(FILTER('Sales Table','Sales Table'[Item Code]=7 && 'Sales Table'[Period]=202404)))
It returns 3 as there are 3 transactions.
In your formula there are 2 issues: it is checking for all rows that are either MacBook Pro OR period 202204. We need AND condition instead of OR.
Another issue is that you grouped based on period/item in virutal table, so it will group by Macbook Pro 202204, returning only 1 row count.
If you used summarize, you would need to add another group by transaction to get count of transactions.
Cheers,
Nemanja Andic
2 Replies
- nandic
Resident Rockstar
gbarr12345 you could try this formula:
CALCULATE(COUNTROWS(FILTER('Sales Table','Sales Table'[Item Code]=7 && 'Sales Table'[Period]=202404)))
It returns 3 as there are 3 transactions.
In your formula there are 2 issues: it is checking for all rows that are either MacBook Pro OR period 202204. We need AND condition instead of OR.
Another issue is that you grouped based on period/item in virutal table, so it will group by Macbook Pro 202204, returning only 1 row count.
If you used summarize, you would need to add another group by transaction to get count of transactions.
Cheers,
Nemanja Andic- gbarr12345
Post Prodigy
That worked! Thank you so much Nemanja.