Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

Trying to display a list of meter readings where the datasource has only 1 reading per client

Posted on by 359

@WarrenBelz I have a Sharepoint list called MeterReadings. Each record is assigned a clientname and a reading (usually there will be a reading every 4-6 months so in a year there should be 3 readings.

 

I want to display a Gallery list of records where there is only 1 reading for a clientname. My sharepoint list is over 5000 records so delegation is going to be a problem.

 

I know I need to use Count or CountRows and GroupBy but I just can't seem get my head around how to do it

Any advice greatly appreciated thank you 🙂

  • bobgodin Profile Picture
    bobgodin 359 on at
    Re: Trying to display a list of meter readings where the datasource has only 1 reading per client

    Hi @WarrenBelz 

    Been checking data all morning and I have it working thanks to your assistance. I had to change the sort by in the first part of the code from ID to meterref.Ascending - then it is giving me correct results.

     

    I wasn't thinking straight when I commented earlier about the number of records expected - the wider the dates the LESS number of records because we have a larger time span and so likely to have MORE THAN 1 reading per meterref!

     

    thanks again Warren 🙂

  • Verified answer
    WarrenBelz Profile Picture
    WarrenBelz 143,532 on at
    Re: Trying to display a list of meter readings where the datasource has only 1 reading per client

    Hi @bobgodin ,

    So you are looking for instances where there is only one meterref for each group between  the dates ?

    With(
     {
     _Data: 
     Sort(
     Filter(
     MeterReadings,
     readdate >= (DatePickerFrom.SelectedDate) && 
     readdate <= DatePickerTo.SelectedDate && 
     (
     StartsWith(
     meterref,
     SearchBox.Text
     ) || 
     StartsWith(
     auth,
     SearchBox.Text
     )
     )
     ),
     ID,
     SortOrder.Descending
     )
     },
     SortByColumns(
     AddColumns(
     Filter(
     GroupBy(
     _Data,
     "meterref",
     "Grouped"
     ),
     CountRows(Grouped) = 1
     ),
     "clientname",
     First(Grouped).clientname,
     "clientref",
     First(Grouped).clientref,
     "reading",
     First(Grouped).reading,
     "readdate",
     First(Grouped).readdate,
     "dialscode",
     First(Grouped).dialscode,
     "wma",
     First(Grouped).wma,
     "auth",
     First(Grouped).auth,
     "comments",
     First(Grouped).comments
     ),
     "meterref"
     )
    )
  • bobgodin Profile Picture
    bobgodin 359 on at
    Re: Trying to display a list of meter readings where the datasource has only 1 reading per client

    Hi @WarrenBelz 

    I don't really know how to explain it any better, however I will give you the real life scenario and see if that helps:

    • Client submits a meter reading for Water they have used - they supply a readdate, a reading, the meterref (meter identifier) and their clientref
    • The Client is required to submit a reading once a year (usually around July)
    • To be able to calculate how much water they have used in 1 year we obviously need 2 readings - we subtract the Min(reading) from the Max(reading) to get the usage
    • Other constraints come into play then and we have to establish whether they have "OverUsed" or not
    • Those clients with a meterref that has only 1 reading (between specified dates) - we can't calculate whether they have "OverUsed" or their meter is broken etc but these are the ones we have to investigate
    • So we are looking for data where there is only 1 record per meterref with a readdate between specified dates and the reading is not blank. Meaning that the client has not submitted more than 1 reading.

     

    hope this is a bit clearer lol

  • WarrenBelz Profile Picture
    WarrenBelz 143,532 on at
    Re: Trying to display a list of meter readings where the datasource has only 1 reading per client

    Hi @bobgodin ,

    Sorry but a bit unclear as to what you require. What is the "singularity" here - the meterref or the client (or the reading). It can be grouped by whatever you want (including a combintion of more than one field), but I need to know what the "group" consists of.

  • bobgodin Profile Picture
    bobgodin 359 on at
    Re: Trying to display a list of meter readings where the datasource has only 1 reading per client

    Hi @WarrenBelz 

    I have done a bit of digging and I have attached 2 screenshots - one is the sharepoint list and the 2nd is the Powerapp Gallery display:

    bobgodin_0-1701750774583.png

     

    bobgodin_1-1701750940413.png

    Focussing on meterref 10004 and 10060 - notice that the Sharepoint list has 2 readings for each of these meterrefs 

    Notice also that the clientref for each meteref is the same (as is usually the case) and sometimes the reading is the same (in the case of 10004) - even though the reading has the same value there are still 2 readings for that meterref.  It is the readdate that is different per meterref.

    I am thinking that the code may need changing because of the above factors - could you assist please Warren

    thank you

  • bobgodin Profile Picture
    bobgodin 359 on at
    Re: Trying to display a list of meter readings where the datasource has only 1 reading per client

    Hi @WarrenBelz 

    I am checking the Sharepoint list for single reads at the moment to see if that matches up with the results from the app. Thanks again for your help

  • WarrenBelz Profile Picture
    WarrenBelz 143,532 on at
    Re: Trying to display a list of meter readings where the datasource has only 1 reading per client

    Hi @bobgodin ,

    Assuming your read date pickers were set to 4/12/22 until 4/12/23 then that should be the outcome. I am also assuming you have "" (empty string) as the Default of your Search Box to avoid any filtering from there.

  • bobgodin Profile Picture
    bobgodin 359 on at
    Re: Trying to display a list of meter readings where the datasource has only 1 reading per client

    Hi @WarrenBelz 

    1456789 doesn't have a reading (or its blank)

    1765432 has 2 readings (one in 2021 and one in 2022)

    The only record that satisfies the criteria is 1234567 (which has only 1 reading)

  • WarrenBelz Profile Picture
    WarrenBelz 143,532 on at
    Re: Trying to display a list of meter readings where the datasource has only 1 reading per client

    Hi @bobgodin ,

    Sorry a bit lost here - why are not meterref 1456789 and 1765432 being included ?

  • bobgodin Profile Picture
    bobgodin 359 on at
    Re: Trying to display a list of meter readings where the datasource has only 1 reading per client

    Hi @WarrenBelz I probably haven't explained the situation well enough. I will give you a sample of the data in my Sharepoint list and then another list displaying what I would like the outcome to be:

     

    meterrefclientrefclientnamewmadialscodeauthreaddatereading
    123456799587Fred BloggsDawson Valleym5305982B4/12/20230876543
    145678999871Barney Rubble & CoDawson Valleym54045678A  
    176543288755Fred Flintstone Pty LtdAtherton Groundwater Aream420323113A1/11/2021198765
    176543288755Fred Flintstone Pty LtdAtherton Groundwater Aream420323113A1/11/2022201123
            
            
            
    meterrefclientrefclientnamewmadialscodeauthreaddatereading
    123456799587Fred BloggsDawson Valleym5305982B4/12/20230876543
            

    hope this helps Warren!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,532

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,050

Leaderboard