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
Coder
Frequent Visitor

Counts Based On Tran Sum Totals As Of A Date

Desired Visual Outcome:

 

WEEKTYPE 1TYPE 2TYPE 3TOTAL
3/1/200101
3/8/201102
3/15/201113
3/22/201102
3/29/201102

*Edit: Fixing so matrix shows desired logic.

 

I need to create a matrix where the WEEK is in the Rows section, TYPE is in the Columns section, and a measure needs to be in the Values section. The measure counts ACCTs once per row if the total of TRAN up to that date is above 0. Example: 1 in cell intersecting TYPE 1 and 3/15/2020 means by this date there is one ACCT that has sum of TRAN > 0 measured from the beginning of the TRANS table (see below).

 

I have a DATES table that has consecutive calendar days in DATE field and a corresponding end of week WEEK date (Shown truncated below).

DATEWEEK
3/1/203/1/20
3/2/203/8/20
3/3/203/8/20

 

I have a TRANS table:

INDEXACCTTDTYPETRAN
113/1/202100
213/2/202-100
313/5/202200
423/4/201150
523/9/2010
633/15/203500
733/16/203-250
833/16/203-250
933/23/203100
1033/26/203-100

Note: INDEX counts each row in table. TRANS is ordered by ACCT and TD. Each ACCT can be only one TYPE. There can be multiple transactions on same day, but ACCT should show up only once per WEEK (row on matrix). ACCT should show up on matrix even there are no transactions for the corresponding WEEK date if the total TRAN up to that point for the ACCT is >0.

 

There is a relationship between tables: 'TRANS'[TD] *:1 'DATES'[DATE]

 

Matrix should also show only the latest 5 WEEK dates (but getting measure is priority).

 

Please help me formulate the DAX to create a measure that can go in the Values section of the matrix visual.

1 ACCEPTED SOLUTION

Hi,

If that be your logic, then the result should be this.  Download the PBI file from here.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

9 REPLIES 9
amitchandak
Super User
Super User

@Coder , What I got till now. We can use distinctcount of Type

Or create a new concatenated field

Acc+ Type = [Acct]& "-"&[Type]

 

And take a distinctcount of that. For latest 5 weeks you can use relative date slicer

https://docs.microsoft.com/en-us/power-bi/visuals/desktop-slicer-filter-date-range

@Coder I will change measure in @Ashish_Mathur  solution as below so that the Total line at the bottom adds up.

 

Measure = 
COUNTX (
    SUMMARIZE (
        Trans, 
        Trans[ACCT],
        'Calendar'[WEEK]
    ),
    IF ( [MTD values] > 0, 1)
) + 0

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_MathurThanks. This is close to what I want.

 

The counts need to carry over the month and year. So for example if there was an extra transaction for ACCT 3 occurring on 3/29/2020 for 100. The matrix as of 4/12/2020 would show:

WEEKTYPE 1TYPE 2TYPE 3TOTAL
3/1/200101
3/8/201102
3/15/201012
3/22/200000
3/29/200011
4/5/200011
4/12/200011

*Red for the rows that wouldn't show up if the matrix only shows last 5 WEEK dates.

 

Similarly if the matrix was shown around January, the counts would persist from the prior year. Right now it does this only through the end of month.

Hi,

See if this works.  Download the file from here.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

 

@Ashish_MathurThanks for the response. The counts are carrying over from the previous month. However, this is only happening when there is a transaction during the week. For example, if this was the Trans table in the .pbix file (assuming the Calendar table goes to 4/4/2020 in the DATE field):

INDEXACCTTDTYPETRAN
113/1/202100
213/2/202-100
313/5/202200
423/4/201150
523/9/2010
633/15/203500
733/16/203-250
833/16/203-250
933/22/203100
1034/4/2030

 

The matrix in the file shows:

WEEKTYPE 1TYPE 2TYPE 3TOTAL
3/1/200101
3/8/201102
3/15/201012
3/22/200011
3/29/200000
4/5/200011

 

When it needs to be:

WEEKTYPE 1TYPE 2TYPE 3TOTAL
3/1/200101
3/8/201102
3/15/201012
3/22/200011
3/29/200011
4/5/200011

 

The matrix needs to show a 1 for TYPE 3 on 3/29/2020 since ACCT 3 has a positive TRAN total at that point, even though it doesn't have a transaction during that week.

Hi,

If that be your logic, then the result should be this.  Download the PBI file from here.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_MathurYes, that's what I'm looking for! You are right my question had an error in it. Sorry about any confusion this may have caused. I will edit the question so your solution may benefit others who want to do something similar.

 

Thank you!

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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.