Question: I'm using PowerBI desktop and I'm creating a chart to display **average sales per weekday**:

[![enter image description here](https://i.stack.imgur.com/3Oa61.png)](https://i.stack.imgur.com/3Oa61.png)

My data is in the format below:

*(sampled in Excel to remove sensitive information, added colors to facilitate visualization)*

[![sample_data](https://i.stack.imgur.com/jOBGj.png)](https://i.stack.imgur.com/jOBGj.png)

**My problem is**: since each day is broken in 24 rows (hours), my average is wrong by a factor of 24.

For example, if I select January-2019 in the slicer, which has five Tuesdays (weekday code: 2), I want to see on the bar number 2:

* **(sum of amount where weekday = 2) / 5**

Instead, I'm calculating:

* **(sum of amount where weekday = 2) / (24 \* 5)**

---

I can think of some ways to get this right, but they involve custom columns or auxiliary tables. I'm sure there is a simpler answer using DAX and measures, but I'm still learning it. 

How can I correctly calculate this?

Answer: 
Instead of using structures, use TLV mechanism. So for your solution: you can use Type , , Count of Type, Length , Value.

1. Define types which is known at both receiver and sender side
2. Define your message structure as 
Type taking 2 bytes, Count-of-type taking 2 or 4 bytes , Length taking 4 bytes and Value.
3. This is extensible as you can add any number of types in future as long as the type is known at both side. At receiver side if type is not known, they can ignore that TLV.
You should not send `structs` over network protocols (or store them in files, etc). You need to [serialize](https://en.wikipedia.org/wiki/Serialization) them.

But to solve your problem, simply change your send code:

```
//this is what your code looks like, I assume:
write(sockFd, myStructVariable, sizeof(struct MyStruct));

```

to:

```
//be aware of writev(2) if you want to send these in one system call at once, or copy them into one buffer
write(sockFd, myStructVariable.numofarray1elements, sizeof(int));
write(sockFd, myStructVariable.array1, sizeof(MyArray1) * myStructVariable.numofarray1elements);
write(sockFd, myStructVariable.numofarray2elements, sizeof(int));
write(sockFd, myStructVariable.array2, sizeof(MyArray2) * myStructVariable.numofarray2elements);

```

or something similar

Then change your receive code:

```
read(sockFd, myStructVariable.numofarray1elements, sizeof(int));
read(sockFd, myStructVariable.array1, sizeof(MyArray1) * myStructVariable.numofarray1elements);
read(sockFd, myStructVariable.numofarray2elements, sizeof(int));
read(sockFd, myStructVariable.array2, sizeof(MyArray2) * myStructVariable.numofarray2elements);

```

of course, you could also leave the array and counts defined locally and send those instead. Make sure you check for errors, short reads, etc

Take a look at [flatbuffers](https://google.github.io/flatbuffers) as well, this lets you write structures that come with serialization functions