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

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.

Reply
Mike_Mace
Resolver I
Resolver I

Countrows on weekly periods

Happy August-ing developers

Some help from whom can lend an ear

 

I have table A. showing entries data by created date

I have table B. showing historic performance per specific dates

The two date columns have a relationship

 

My DAX calclulated values are definitely not correct. Any ideas?

 

Entries /week column = CALCULATE(COUNTROWS('Entries table'), DATESINPERIOD('Entries table'[Created], Performance[Date], -7, DAY)) 
A. Entries

Entries dates snip to be countrow-ed.JPG

B. Pefromance dates

Performance dates snip.JPG

1 ACCEPTED SOLUTION

Hi @Mike_Mace,

My formula is a measure please create a measure and copy the code into measure expression to use it:

Entries New/week test 2= 
VAR currDate =
    MAX ( 'Performance Table'[Dates] )
RETURN
    CALCULATE (
        COUNTROWS ( 'Entries Table' ),
        FILTER (
            ALLSELECTED ( 'Entries Table'),
            YEAR ( [Created]) = YEAR ( currDate )
                && WEEKNUM ( [Created] ) = WEEKNUM ( currDate )
        )
    )

If you want a calculated column version, you can try to use following calculated column formula: (Notice: calculated column/table did not dynamic changes based on filters/slicers)

Entries New/week test 2 =
CALCULATE (
    COUNTROWS ( 'Entries Table' ),
    FILTER (
        ALLSELECTED ( 'Entries Table' ),
        YEAR ( [Created] ) = YEAR ( EARLIER ( 'Performance Table'[Dates] ) )
            && WEEKNUM ( [Created] ) = WEEKNUM ( EARLIER ( 'Performance Table'[Dates] ) )
    )
)

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

10 REPLIES 10
v-shex-msft
Community Support
Community Support

Hi @Mike_Mace,

I'd like to suggest you use year and weeknum to filter and calculated the records:

formual =
VAR currDate =
    MAX ( Performance[Date] )
RETURN
    CALCULATE (
        COUNTROWS ( 'Entries table' ),
        FILTER (
            ALLSELECTED ( 'Entries table' ),
            YEAR ( [Created] ) = YEAR ( currDate )
                && WEEKNUM ( [Created] ) = WEEKNUM ( currDate )
        )
    )

If the above not help, please provide more detailed information to help us clarify your requirement.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi @v-shex-msft ,

 

Attaching the pbix  on a wetranfer link as my first message was not accurate enough to pass on the query.

https://we.tl/t-QnhaKwwUyq

 

I've removed the relationship between the two datasets and the original formula to calculate all the entries per said week (on performance dataset) seems to work BUT the value for the latest date is not calculated. 

I've manually checked the numbers from the spreadsheet side for that week to be 864 but see on snip it is left empty.

Does formula need another filter?

I've crosschecked another two weeks by checking the number of entries from the spreadsheet manually and the numbers are correct

 

Entries /week column = CALCULATE(COUNTROWS('Entries table'), DATESINPERIOD('Entries table'[Created], Performance[Date], -7, DAY))

 

 
 

snipsnip

 

 

 

Hi @Mike_Mace,

Can you please upload this to onedrive for business? I can't download from the third party web drive that you shared.

Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

HI @Mike_Mace,

Shared content seems to be removed when I access to your link, can you please fix this?
Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi @v-shex-msft ,

 

Of course, here's the right link for it

https://1drv.ms/u/s!Amf63tQXGj5rklkr-5wKw8XgwEK1

 

Hi @Mike_Mace,

My formula is a measure please create a measure and copy the code into measure expression to use it:

Entries New/week test 2= 
VAR currDate =
    MAX ( 'Performance Table'[Dates] )
RETURN
    CALCULATE (
        COUNTROWS ( 'Entries Table' ),
        FILTER (
            ALLSELECTED ( 'Entries Table'),
            YEAR ( [Created]) = YEAR ( currDate )
                && WEEKNUM ( [Created] ) = WEEKNUM ( currDate )
        )
    )

If you want a calculated column version, you can try to use following calculated column formula: (Notice: calculated column/table did not dynamic changes based on filters/slicers)

Entries New/week test 2 =
CALCULATE (
    COUNTROWS ( 'Entries Table' ),
    FILTER (
        ALLSELECTED ( 'Entries Table' ),
        YEAR ( [Created] ) = YEAR ( EARLIER ( 'Performance Table'[Dates] ) )
            && WEEKNUM ( [Created] ) = WEEKNUM ( EARLIER ( 'Performance Table'[Dates] ) )
    )
)

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

hi @v-shex-msft 

The column one is what I was after


Many thanks!

Greg_Deckler
Super User
Super User

@Mike_Mace - You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...

 

Otherwise, Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.