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
AlfredvdM
Regular Visitor

Create a measurement that shows the opening balance of the lowest number per date

Good afternoon, I am fairly new to PowerBi and probably have a simple question. Thank you very much for your response.
Create a measurement that shows the opening balance of the lowest number per date
Eg the lowest index of 1-1-2022 is 12033 , the value shown should then be 3424.31
Eg the lowest index of 2-1-2022 is 12038 , the value shown should then be 3300,21

 

DateNumberDescription Opening BalanceTransactionClosing Balance
1-1-202212034Diversen €                   3.349,31 €                             58.933,81 €              62.283,12
1-1-202212033Schoen €                   3.424,31 €                                   -75,00 €                 3.349,31
1-1-202212035Laars €                 62.283,12 €                               2.593,09 €              64.876,21
1-1-202212037Diversen €                 64.826,21 €                           -61.526,00 €                 3.300,21
1-1-202212036Jas €                 64.876,21 €                                   -50,00 €              64.826,21
2-1-202212039Diversen €                   3.299,21 €                                     -1,00 €                 3.298,21
2-1-202212038Diversen €                   3.300,21 €                                     -1,00 €                 3.299,21
3-1-202212043Broek €                   2.870,82 €                                 -135,45 €                 2.735,37
3-1-202212042Trui €                   2.996,52 €                                 -125,70 €                 2.870,82
3-1-202212041Jas €                   3.170,26 €                                 -173,74 €                 2.996,52
3-1-202212040Jas €                   3.298,21 €                                 -127,95 €                 3.170,26
      
      
  
  
  
1 ACCEPTED SOLUTION
ImkeF
Super User
Super User

Hi @AlfredvdM ,
how do you want this number to be shown? As an additional column to the existing data in each row?
Then you could use this code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dZA9TwMxDIb/S+arG9v58oqYKjbYqhtO6CQqJCrdCX5/46TQXEknO4mf19FzPBrc454skRkMkmWX6/PpZ17W+Su3zE6AMXc+CTMkbQNRYkAy4/CP51xf3z/OlXbkKr2LvknrcPr8Mk3L2uYPhrwwWNFLl2IA6sJx++k8SmU07w3oKZTV1j6g9fkwre2ODHrbJilGW0zuTJHIFcV6TA/AdK+4/uwGyi/IG9Cp26flPH+qmBQtJCoUe3Dqj2LusowOqvVt+T7plEgAX0nyEJuwDoh/chjzUHG5w8gQXZPVAe0NvKooCyOIb8LG8QI=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Number = _t, Description = _t, #" Opening Balance" = _t, Transaction = _t, #"Closing Balance" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Number", Int64.Type}, {"Description", type text}, {" Opening Balance", type number}, {"Transaction", type number}, {"Closing Balance", type number}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Date", "Number", "Description"}, {{"MinOpening", each List.Min([#" Opening Balance"]), type nullable number}, {"Partition", each _, type table [Date=nullable date, Number=nullable number, Description=nullable text, #" Opening Balance"=nullable number, Transaction=nullable number, Closing Balance=nullable number]}}),
    #"Expanded Partition" = Table.ExpandTableColumn(#"Grouped Rows", "Partition", {" Opening Balance", "Transaction", "Closing Balance"}, {" Opening Balance", "Transaction", "Closing Balance"})
in
    #"Expanded Partition"

Please also check the file enclosed.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

4 REPLIES 4
AlfredvdM
Regular Visitor

Hi Imke, That's the right solution. Thanks a Lot!!

gr Alfred

ImkeF
Super User
Super User

Hi @AlfredvdM ,
yes, my bad.
Please try this solution:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dZA9TwMxDIb/S+arG9v58oqYKjbYqhtO6CQqJCrdCX5/46TQXEknO4mf19FzPBrc454skRkMkmWX6/PpZ17W+Su3zE6AMXc+CTMkbQNRYkAy4/CP51xf3z/OlXbkKr2LvknrcPr8Mk3L2uYPhrwwWNFLl2IA6sJx++k8SmU07w3oKZTV1j6g9fkwre2ODHrbJilGW0zuTJHIFcV6TA/AdK+4/uwGyi/IG9Cp26flPH+qmBQtJCoUe3Dqj2LusowOqvVt+T7plEgAX0nyEJuwDoh/chjzUHG5w8gQXZPVAe0NvKooCyOIb8LG8QI=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Number = _t, Description = _t, #"Opening Balance" = _t, Transaction = _t, #"Closing Balance" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Number", Int64.Type}, {"Description", type text}, {"Opening Balance", type number}, {"Transaction", type number}, {"Closing Balance", type number}}),
#"Grouped Rows" = Table.Group(
        #"Changed Type", 
        {"Date"}, 
        {
            {"OpeningPerDate", each Table.Buffer(Table.Sort(_, {"Number", Order.Ascending})){0}[Opening Balance]}, 
            {"ClosingPerDate", each Table.Buffer(Table.Sort(_, {"Number", Order.Descending})){0}[Closing Balance]}, 
            {
                "Partition", 
                each _, 
                type table [
                    Date = nullable date, 
                    Number = nullable number, 
                    Description = nullable text, 
                    #" Opening Balance" = nullable number, 
                    Transaction = nullable number, 
                    Closing Balance = nullable number
                ]
            }
        }
    ), 
    #"Expanded Partition" = Table.ExpandTableColumn(
        #"Grouped Rows", 
        "Partition", 
        {"Opening Balance", "Transaction", "Closing Balance"}, 
        {"Opening Balance", "Transaction", "Closing Balance"}
    )
in
    #"Expanded Partition"

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

AlfredvdM
Regular Visitor

Hi Imke,

Thanks a lot for yout input.  I probably have to redefine my question.

1. There are several transactions per date

2. Therefore I need the correct openingbalance for that specific date.

3. The correct openingbalance for that date is the one with the lowest value in column [number].

    Note: not the minimum value of the openingsbalance itself

 

DateNumberDescription Opening Balance  Transaction  Closing Balance  OpeningBalancePerDate  ClosingBalancePerDate 
1-1-202212033Schoen €                    3.424,31 €                 -75,00 €                 3.349,31 €              3.424,31 €                   3.300,21
1-1-202212034Diversen €                    3.349,31 €           58.933,81 €               62.283,12 €              3.424,31 €                   3.300,21
1-1-202212035Laars €                 62.283,12 €             2.593,09 €               64.876,21 €              3.424,31 €                   3.300,21
1-1-202212036Jas €                 64.876,21 €                 -50,00 €               64.826,21 €              3.424,31 €                   3.300,21
1-1-202212037Diversen €                 64.826,21 €         -61.526,00 €                 3.300,21 €              3.424,31 €                   3.300,21
2-1-202212038Diversen €                    3.300,21 €                    -1,00 €                 3.299,21 €              3.300,21 €                   3.298,21
2-1-202212039Diversen €                    3.299,21 €                    -1,00 €                 3.298,21 €              3.300,21 €                   3.298,21

So, per 1-1-2022 is the correct openingbalance the one with number 12033 (the lowest number of date 1-1-22), and that is 3.424,31.

Why? If I add the transactions to the opening balance, I get the correct closing balance for that specific date. 

I hope I explained it clearly.

 

Many thanks in advance for the effort.

 

Gr Alfred

 

ImkeF
Super User
Super User

Hi @AlfredvdM ,
how do you want this number to be shown? As an additional column to the existing data in each row?
Then you could use this code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dZA9TwMxDIb/S+arG9v58oqYKjbYqhtO6CQqJCrdCX5/46TQXEknO4mf19FzPBrc454skRkMkmWX6/PpZ17W+Su3zE6AMXc+CTMkbQNRYkAy4/CP51xf3z/OlXbkKr2LvknrcPr8Mk3L2uYPhrwwWNFLl2IA6sJx++k8SmU07w3oKZTV1j6g9fkwre2ODHrbJilGW0zuTJHIFcV6TA/AdK+4/uwGyi/IG9Cp26flPH+qmBQtJCoUe3Dqj2LusowOqvVt+T7plEgAX0nyEJuwDoh/chjzUHG5w8gQXZPVAe0NvKooCyOIb8LG8QI=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Number = _t, Description = _t, #" Opening Balance" = _t, Transaction = _t, #"Closing Balance" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Number", Int64.Type}, {"Description", type text}, {" Opening Balance", type number}, {"Transaction", type number}, {"Closing Balance", type number}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Date", "Number", "Description"}, {{"MinOpening", each List.Min([#" Opening Balance"]), type nullable number}, {"Partition", each _, type table [Date=nullable date, Number=nullable number, Description=nullable text, #" Opening Balance"=nullable number, Transaction=nullable number, Closing Balance=nullable number]}}),
    #"Expanded Partition" = Table.ExpandTableColumn(#"Grouped Rows", "Partition", {" Opening Balance", "Transaction", "Closing Balance"}, {" Opening Balance", "Transaction", "Closing Balance"})
in
    #"Expanded Partition"

Please also check the file enclosed.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

Top Solution Authors
Top Kudoed Authors