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
ToddMate
Helper II
Helper II

Grouping by dates & summing the charge

Hi,

 

I'm in need of assistance, i have a table containing service numbers, charge from (Date) and charge to (Date), an invoice period and an amount.

 

What i need to achieve is to determine the SUM of the amount where the charge from (date) and charge to (date) are the same, and then group these by service number and invoice period within a Matric (Service Number is the Row and Invoice Period is the Column)

 

Annotation 2019-09-18 141949.png

For the life of me i am unable to achieve the desired result, can anyone help here?

I have the sample PBI file in need, however i am unsure how to attached it to this post.

1 ACCEPTED SOLUTION

Now that is a bit more tricky question. Thanks for the sample-file, for the purpose of testing it would have been nice if there some cases where there were no matching to/from-rows Smiley Happy

A couple of different ways to solve this. You could create a calculated column, where 1 indicates matching rows and 0 rows without match. Then add amount/charge to the matrix visual, and filter on flag=1

matchingFlag =
VAR sn = ImportFile[ServiceNumber]
VAR cf = ImportFile[Charge From]
VAR ct = ImportFile[Charge To]
VAR ip = ImportFile[Invoice Period]
RETURN
    IF (
        COUNTROWS (
            FILTER (
                ImportFile;
                ImportFile[ServiceNumber] = sn
                    && ImportFile[Charge From] = cf
                    && ImportFile[Charge To] = ct
                    && ImportFile[Invoice Period] = ip
            )
        ) > 1;
        1;
        0
    )



Or you can create this measure

amount =
CALCULATE (
    SUM ( ImportFile[Charge] );
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE (
                ImportFile;
                ImportFile[Invoice Period];
                ImportFile[ServiceNumber];
                ImportFile[Charge From];
                ImportFile[Charge To]
            );
            "numberOfRows"; CALCULATE ( COUNTROWS ( ImportFile ) )
        );
        [numberOfRows] > 1
    )
)


Cheers,
S

View solution in original post

7 REPLIES 7
v-eachen-msft
Community Support
Community Support

Hi @ToddMate ,

 

You can create a new measure like this:

Measure =
CALCULATE (
    SUM ( ImportFile[Charge] ),
    ALLEXCEPT (
        ImportFile,
        ImportFile[Charge From],
        ImportFile[Charge To],
        ImportFile[ServiceNumber],
        ImportFile[Invoice Period]
    )
)
Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
ToddMate
Helper II
Helper II

Hi,

Having reread my post i have been vague and inaccurate in my requirements in that what i need to achieve. My apologies for this.

 

What i actually need to achieve is to sum the charge column were the Charge From and Charge To dates are the same as other rows. The context will be applied in the matrix by Service Number and Invoice Period.

The matrix would have Service Number as rows and Invoice Period as columns the values would be the sum of the charge. In the highlighted example below this would return $2.80 for the 01/05/2017 Invoice Period. (Service Number AX1542888)

If there are no matching rows then nothing would be shown. 

 

tempsnip.png

 

This is a link to the above data in a sample file on my onedrive (password = power). 
https://1drv.ms/u/s!AqPKTVzB9hvp9l_Yw-WOCeNJiq6W?e=CllYPN

Regards
Todd

Now that is a bit more tricky question. Thanks for the sample-file, for the purpose of testing it would have been nice if there some cases where there were no matching to/from-rows Smiley Happy

A couple of different ways to solve this. You could create a calculated column, where 1 indicates matching rows and 0 rows without match. Then add amount/charge to the matrix visual, and filter on flag=1

matchingFlag =
VAR sn = ImportFile[ServiceNumber]
VAR cf = ImportFile[Charge From]
VAR ct = ImportFile[Charge To]
VAR ip = ImportFile[Invoice Period]
RETURN
    IF (
        COUNTROWS (
            FILTER (
                ImportFile;
                ImportFile[ServiceNumber] = sn
                    && ImportFile[Charge From] = cf
                    && ImportFile[Charge To] = ct
                    && ImportFile[Invoice Period] = ip
            )
        ) > 1;
        1;
        0
    )



Or you can create this measure

amount =
CALCULATE (
    SUM ( ImportFile[Charge] );
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE (
                ImportFile;
                ImportFile[Invoice Period];
                ImportFile[ServiceNumber];
                ImportFile[Charge From];
                ImportFile[Charge To]
            );
            "numberOfRows"; CALCULATE ( COUNTROWS ( ImportFile ) )
        );
        [numberOfRows] > 1
    )
)


Cheers,
S

amaleranda
Post Patron
Post Patron

hi @ToddMate 

 

Capture.PNG

 

Please accept this as a solution if it resolver your issue, 

amaleranda
Post Patron
Post Patron

Hi @ToddMate 

 

have you tried make charge column default summrisation to be sum and then put them in a tabel. 

 

that is what I did in the below tabel. there are only two line items in the details tabel that have same from and to date. 

 

Capture.PNG

 

 

 

sturlaws
Resident Rockstar
Resident Rockstar

Hi,

 

you can share the file by uploading it to onedrive/dropbox/other and post the link to the file.

Cheers,

S

But, assuming I have understood you requirements, your measure could be written like this

Amount =
CALCULATE (
    SUM ( Table[charge] );
    FILTER ( Table; Table[charge from] = Table[charge to] )
)

and add this measure together with invoice period and servicenumber to your matrix visual

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.