Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
gbarr12345
Post Patron
Post Patron

MacBook 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_0-1716238679324.png

 

gbarr12345_1-1716238688260.png

 

1 ACCEPTED SOLUTION
nandic
Memorable Member
Memorable Member

@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

View solution in original post

2 REPLIES 2
nandic
Memorable Member
Memorable Member

@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

That worked! Thank you so much Nemanja.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.